class Bio::NCBIDB
Public Class Methods
new(entry, tagsize)
click to toggle source
The entire entry is passed as a String. The length of the tag field is passed as an Integer. Parses the entry roughly by the entry2hash method and returns a database object.
# File lib/bio/db.rb, line 256 def initialize(entry, tagsize) @tagsize = tagsize @orig = entry2hash(entry.strip) # Hash of the original entry @data = {} # Hash of the parsed entry end
Private Instance Methods
entry2hash(entry)
click to toggle source
Returns the contents of the entry as a Hash with the top level tags as its keys.
# File lib/bio/db.rb, line 278 def entry2hash(entry) hash = Hash.new('') fields = toptag2array(entry) fields.each do |field| tag = tag_get(field) hash[tag] += field end return hash end
subtag2array(str)
click to toggle source
Splits a field into an Array of Strings at the level of sub tags.
# File lib/bio/db.rb, line 271 def subtag2array(str) sep = "\001" str.gsub(/\n(\s{1,#{@tagsize-1}}\S)/, "\n#{sep}\\1").split(sep) end
toptag2array(str)
click to toggle source
Splits an entry into an Array of Strings at the level of top tags.
# File lib/bio/db.rb, line 265 def toptag2array(str) sep = "\001" str.gsub(/\n([A-Za-z\/\*])/, "\n#{sep}\\1").split(sep) end