class Bio::FlatFile::Splitter::LineOriented
A splitter for line oriented text data.
The given class's object must have following methods.
Klass#add_header_line(line) Klass#add_line(line)
where 'line' is a string. They normally returns self. If the line is not suitable to add to the current entry, nil or false should be returned. Then, the line is treated as (for add_header_line) the entry data or (for add_line) the next entry's data.
Attributes
flag_to_fetch_header[RW]
flag to fetch header
Public Class Methods
new(klass, bstream)
click to toggle source
Creates a new splitter.
- klass
-
database class
- bstream
-
input stream. It must be a BufferedInputStream object.
Calls superclass method
Bio::FlatFile::Splitter::Template.new
# File lib/bio/io/flatfile/splitter.rb, line 214 def initialize(klass, bstream) super(klass, bstream) self.flag_to_fetch_header = true end
Public Instance Methods
get_entry()
click to toggle source
get an entry and return the entry as a string
# File lib/bio/io/flatfile/splitter.rb, line 225 def get_entry if e = get_parsed_entry then entry else e end end
get_parsed_entry()
click to toggle source
get an entry and return the entry as a data class object
# File lib/bio/io/flatfile/splitter.rb, line 234 def get_parsed_entry p0 = stream_pos() ent = @dbclass.new() lines = [] line_overrun = nil if flag_to_fetch_header then while line = stream.gets("\n") unless ent.add_header_line(line) then line_overrun = line break end lines.push line end stream.ungets(line_overrun) if line_overrun line_overrun = nil self.flag_to_fetch_header = false end while line = stream.gets("\n") unless ent.add_line(line) then line_overrun = line break end lines.push line end stream.ungets(line_overrun) if line_overrun p1 = stream_pos() return nil if lines.empty? self.entry_start_pos = p0 self.entry = lines.join('') self.parsed_entry = ent self.entry_ended_pos = p1 return ent end
rewind()
click to toggle source
rewinds the stream
Calls superclass method
Bio::FlatFile::Splitter::Template#rewind
# File lib/bio/io/flatfile/splitter.rb, line 275 def rewind ret = super self.flag_to_fetch_header = true ret end
skip_leader()
click to toggle source
do nothing
# File lib/bio/io/flatfile/splitter.rb, line 220 def skip_leader nil end