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.
Creates a new splitter.
klass |
database class |
bstream |
input stream. It must be a BufferedInputStream object. |
# File lib/bio/io/flatfile/splitter.rb, line 214 def initialize(klass, bstream) super(klass, bstream) self.flag_to_fetch_header = true end
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 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
Generated with the Darkfish Rdoc Generator 2.