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.

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
214 def initialize(klass, bstream)
215   super(klass, bstream)
216   self.flag_to_fetch_header = true
217 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
225 def get_entry
226   if e = get_parsed_entry then
227     entry
228   else
229     e
230   end
231 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
234 def get_parsed_entry
235   p0 = stream_pos()
236   ent = @dbclass.new()
237 
238   lines = []
239   line_overrun = nil
240 
241   if flag_to_fetch_header then
242     while line = stream.gets("\n")
243       unless ent.add_header_line(line) then
244         line_overrun = line
245         break
246       end
247       lines.push line
248     end
249     stream.ungets(line_overrun) if line_overrun
250     line_overrun = nil
251     self.flag_to_fetch_header = false
252   end
253       
254   while line = stream.gets("\n")
255     unless ent.add_line(line) then
256       line_overrun = line
257       break
258     end
259     lines.push line
260   end
261   stream.ungets(line_overrun) if line_overrun
262   p1 = stream_pos()
263 
264   return nil if lines.empty?
265 
266   self.entry_start_pos = p0
267   self.entry = lines.join('')
268   self.parsed_entry = ent
269   self.entry_ended_pos = p1
270 
271   return ent
272 end
rewind() click to toggle source

rewinds the stream

    # File lib/bio/io/flatfile/splitter.rb
275 def rewind
276   ret = super
277   self.flag_to_fetch_header = true
278   ret
279 end
skip_leader() click to toggle source

do nothing

    # File lib/bio/io/flatfile/splitter.rb
220 def skip_leader
221   nil
222 end