class MgNu::Genbank::Source

Attributes

common_name[RW]
lineage[RW]
organism[RW]

Public Class Methods

new(common_name = nil, organism = '', lineage = '') click to toggle source
# File lib/mgnu/genbank/source.rb, line 6
def initialize(common_name = nil, organism = '', lineage = '')
  @common_name = common_name
  @organism = organism
  @lineage = lineage
end
parse(buffer) click to toggle source

class method for parsing a buffer of Source data

# File lib/mgnu/genbank/source.rb, line 13
def self.parse(buffer)
  s = Source.new
  buffer.each do |line|
    if line =~ /^SOURCE\s+(.+)$/
      s.common_name = Regexp.last_match[1].strip.squeeze(' ')
    elsif line =~ /ORGANISM\s+(.+)/
      s.organism += Regexp.last_match[1].strip.squeeze(' ')
    elsif line =~ /[\w]+;\s/ # lineage line reached
      temp = line.strip.squeeze(' ')
      s.lineage += s.lineage.empty? ? temp : " #{temp}"
    end
  end
  s.lineage.chop! if s.lineage =~ /(.+)\.$/ # remove period at the end
  s
end

Public Instance Methods

to_s() click to toggle source
# File lib/mgnu/genbank/source.rb, line 29
def to_s
  out = ''
  out << "#{'SOURCE'.ljust(12)}#{common_name}\n"
  out << "  #{'ORGANISM'.ljust(10)}#{organism.print_multiline}\n"
  out << ''.ljust(12) # first lineage line
  out << lineage.print_multiline unless lineage.empty?
  out << '.'
end