Default splitter. It sees following constants in the given class.
DELIMITER |
(String) delimiter indicates the end of a entry. |
FLATFILE_HEADER |
(String) start of a entry, located on head of a line. |
DELIMITER_OVERRUN |
(Integer) excess read size included in DELIMITER. |
Creates a new splitter.
klass |
database class |
bstream |
input stream. It must be a BufferedInputStream object. |
# File lib/bio/io/flatfile/splitter.rb, line 128 def initialize(klass, bstream) super(klass, bstream) @delimiter = klass::DELIMITER rescue nil @header = klass::FLATFILE_HEADER rescue nil # for specific classes' benefit unless header if (defined?(Bio::GenBank) and klass == Bio::GenBank) or (defined?(Bio::GenPept) and klass == Bio::GenPept) @header = 'LOCUS ' end end @delimiter_overrun = klass::DELIMITER_OVERRUN rescue nil end
gets a entry
# File lib/bio/io/flatfile/splitter.rb, line 180 def get_entry p0 = stream_pos() e = stream.gets(@delimiter) if e and @delimiter_overrun then if e[-@delimiter.size, @delimiter.size ] == @delimiter then overrun = e[-@delimiter_overrun, @delimiter_overrun] e[-@delimiter_overrun, @delimiter_overrun] = '' stream.ungets(overrun) end end p1 = stream_pos() self.entry_start_pos = p0 self.entry = e self.entry_ended_pos = p1 return entry end
Skips leader of the entry.
If @header is not nil, it reads till the contents of @header comes at the head of a line. If correct FLATFILE_HEADER is found, returns true. Otherwise, returns nil.
# File lib/bio/io/flatfile/splitter.rb, line 158 def skip_leader if @header then data = '' while s = stream.gets(@header) data << s if data.split(/[\r\n]+/)[-1] == @header then stream.ungets(@header) return true end end # @header was not found. For safety, # pushes back data with removing white spaces in the head. data.sub(/\A\s+/, '') stream.ungets(data) return nil else stream.skip_spaces return nil end end
Generated with the Darkfish Rdoc Generator 2.