[BioRuby-cvs] bioruby/lib/bio/sequence format.rb,1.4.2.7,1.4.2.8

Naohisa Goto ngoto at dev.open-bio.org
Tue Jun 17 15:50:07 UTC 2008


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

Modified Files:
      Tag: BRANCH-biohackathon2008
	format.rb 
Log Message:
* In the wrap method, changed to recognize "\n" in given string.
* Some helper methods are added to help formatting date string.


Index: format.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/sequence/format.rb,v
retrieving revision 1.4.2.7
retrieving revision 1.4.2.8
diff -C2 -d -r1.4.2.7 -r1.4.2.8
*** format.rb	4 Mar 2008 11:10:28 -0000	1.4.2.7
--- format.rb	17 Jun 2008 15:50:05 -0000	1.4.2.8
***************
*** 285,305 ****
    def wrap_and_split_lines(str, width)
      result = []
!     left = str.dup
!     while left and left.length > width
!       line = nil
!       width.downto(1) do |i|
!         if left[i..i] == ' ' or /[\,\;]/ =~ left[(i-1)..(i-1)]  then
!           line = left[0..(i-1)].sub(/ +\z/, '')
!           left = left[i..-1].sub(/\A +/, '')
!           break
          end
        end
!       if line.nil? then
!         line = left[0..(width-1)]
!         left = left[width..-1]
!       end
!       result << line
      end
-     result << left if left and !(left.to_s.empty?)
      return result
    end
--- 285,309 ----
    def wrap_and_split_lines(str, width)
      result = []
!     lefts = str.chomp.split(/(?:\r\n|\r|\n)/)
!     lefts.each do |left|
!       left.rstrip!
!       while left and left.length > width
!         line = nil
!         width.downto(1) do |i|
!           if left[i..i] == ' ' or /[\,\;]/ =~ left[(i-1)..(i-1)]  then
!             line = left[0..(i-1)].sub(/ +\z/, '')
!             left = left[i..-1].sub(/\A +/, '')
!             break
!           end
          end
+         if line.nil? then
+           line = left[0..(width-1)]
+           left = left[width..-1]
+         end
+         result << line
+         left = nil if  left.to_s.empty?
        end
!       result << left if left
      end
      return result
    end
***************
*** 320,323 ****
--- 324,352 ----
    end
  
+   #--
+   # internal use only
+   MonthStr = [ nil, 
+                'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
+                'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'
+              ].collect { |x| x.freeze }.freeze
+   #++
+ 
+   # formats a date from Date, DateTime, or Time object, or String.
+   def format_date(d)
+     begin
+       yy = d.year
+       mm = d.month
+       dd = d.day
+     rescue NoMethodError, NameError, ArgumentError, TypeError
+       return sprintf("%-11s", d)
+     end
+     sprintf("%02d-%-3s-%04d", dd, MonthStr[mm], yy)
+   end
+ 
+   # null date
+   def null_date
+     Date.new(0, 1, 1)
+   end
+ 
  end #module INSDFeatureHelper
  




More information about the bioruby-cvs mailing list