[BioRuby-cvs] bioruby/lib/bio/shell object.rb,1.1,1.2

Katayama Toshiaki k at dev.open-bio.org
Sun Dec 24 08:40:02 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio/shell
In directory dev.open-bio.org:/tmp/cvs-serv9600

Modified Files:
	object.rb 
Log Message:
* skeletal attempt for object formatting


Index: object.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/object.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** object.rb	27 Feb 2006 09:16:13 -0000	1.1
--- object.rb	24 Dec 2006 08:40:00 -0000	1.2
***************
*** 10,15 ****
  #
  
- require 'cgi'
  require 'pp'
  
  ### Object extention
--- 10,16 ----
  #
  
  require 'pp'
+ require 'cgi'
+ require 'yaml'
  
  ### Object extention
***************
*** 19,52 ****
    attr_accessor :memo
  
!   # *TODO*
!   def to_html
!     if self.is_a?(String)
!       "<pre>" + self + "</pre>"
      else
!       str = ""
!       PP.pp(self, str)
!       "<pre>" + str + "</pre>"
!       #"<pre>" + CGI.escapeHTML(str) + "</pre>"
!       #self.inspect
!       #"<pre>" + self.inspect + "</pre>"
!       #"<pre>" + self.to_s + "</pre>"
      end
    end
  end
  
! =begin
! module Bio
!   class DB
!     def to_html
!       html = ""
!       html += "<table>"
!       @data.each do |k, v|
!         html += "<tr><td>#{k}</td><td>#{v}</td></tr>"
!       end
!       html += "</table>"
      end
    end
  end
- =end
  
-  
--- 20,71 ----
    attr_accessor :memo
  
!   def output(format = :yaml)
!     case format
!     when :yaml
!       self.to_yaml
!     when :html
!       format_html
!     when :inspect
!       format_pp
!     when :png
!       # *TODO*
!     when :svg
!       # *TODO*
!     when :graph
!       # *TODO* (Gruff, RSRuby etc.)
      else
!       #self.inspect.to_s.fold(80)
!       self.to_s
      end
    end
+ 
+   private
+ 
+   def format_html
+     "<pre>#{CGI.escapeHTML(format_pp)}</pre>"
+   end
+ 
+   def format_pp
+     str = ""
+     PP.pp(self, str)
+     return str
+   end
+ 
  end
  
! class Hash
! 
!   private
! 
!   def format_html
!     html = ""
!     html += "<table>"
!     @data.each do |k, v|
!       html += "<tr><td>#{k}</td><td>#{v}</td></tr>"
      end
+     html += "</table>"
+     return html
    end
+ 
  end
  




More information about the bioruby-cvs mailing list