class Bio::DB
Public Class Methods
# File lib/bio/db.rb, line 156 def self.open(filename, *mode, &block) Bio::FlatFile.open(self, filename, *mode, &block) end
Public Instance Methods
Returns an entry identifier as a String. This method must be implemented in every database classes by overriding this method.
# File lib/bio/db.rb, line 162 def entry_id raise NotImplementedError end
Returns true or false - wether the entry contains the field of the given tag name.
# File lib/bio/db.rb, line 173 def exists?(tag) @orig.include?(tag) end
Similar to the get method, however, fetch returns the content of the field without its tag and any extra white spaces stripped.
# File lib/bio/db.rb, line 184 def fetch(tag, skip = 0) field = @orig[tag].split(/\n/, skip + 1).last.to_s truncate(field.gsub(/^.{0,#{@tagsize}}/,'')) end
Returns an intact field of the tag as a String.
# File lib/bio/db.rb, line 178 def get(tag) @orig[tag] end
Private Instance Methods
Returns the content of the field as a String like the fetch method. Furthermore, #field_fetch stores the result in the @data hash.
# File lib/bio/db.rb, line 214 def field_fetch(tag, skip = 0) unless @data[tag] @data[tag] = fetch(tag, skip) end return @data[tag] end
Returns an Array containing each line of the field without a tag. #lines_fetch also stores the result in the @data hash.
# File lib/bio/db.rb, line 223 def lines_fetch(tag) unless @data[tag] list = [] lines = get(tag).split(/\n/) lines.each do |line| data = tag_cut(line) if data[/^\S/] # next sub field list << data else # continued sub field data.strip! if list.last[/\-$/] # folded list[-1] += data else list[-1] += " #{data}" # rest of list end end end @data[tag] = list end @data[tag] end
Returns a String of the field without a tag name.
# File lib/bio/db.rb, line 206 def tag_cut(str) str ||= "" str[0,@tagsize] = '' return str end
Returns a tag name of the field as a String.
# File lib/bio/db.rb, line 200 def tag_get(str) str ||= "" return str[0,@tagsize].strip end
Returns a String with successive white spaces are replaced by one space and stripeed.
# File lib/bio/db.rb, line 194 def truncate(str) str ||= "" return str.gsub(/\s+/, ' ').strip end