class Mspire::Sequest::Sqt::Header

Inherits from hash, so all header stuff can be accessed by key. Multiline values will be pushed into an array. All header values are stored as (newline-removed) strings!

Constants

Arrayed

These will be in arrays no matter what: StaticMod, DynamicMod, Comment Any other keys repeated will be shoved into an array; otherwise a string

HeaderKeys
KeysToAtts
Leader

Public Instance Methods

from_handle(fh) click to toggle source
# File lib/mspire/sequest/sqt.rb, line 175
def from_handle(fh)
  Arrayed.each do |ky|
    self[ky] = []
  end
  pos = fh.pos 
  lines = []
  loop do 
    line = fh.gets
    if line && (line[0,1] == Mspire::Sequest::Sqt::Header::Leader )
      lines << line
    else # reset the fh.pos and we're done
      fh.pos = pos
      break
    end
    pos = fh.pos 
  end
  from_lines(lines)
end
from_lines(array_of_header_lines) click to toggle source
# File lib/mspire/sequest/sqt.rb, line 194
def from_lines(array_of_header_lines)
  array_of_header_lines.each do |line|
    line.chomp!
    (ky, *rest) = line.split(Mspire::Sequest::Sqt::Delimiter)[1..-1]
    # just in case they have any tabs in their field
    value = rest.join(Mspire::Sequest::Sqt::Delimiter)
    if Arrayed.include?(ky)
      self[ky] << value
    elsif self.key? ky  # already exists
      if self[ky].is_a? Array
        self[ky] << value
      else
        self[ky] = [self[ky], value]
      end
    else  # normal
      self[ky] = value
    end
  end
  KeysToAtts.each do |ky,methd|
    self.send("#{methd}=".to_sym, self[ky])
  end
  self
end