Class Bio::FlatFile::Splitter::LineOriented
In: lib/bio/io/flatfile/splitter.rb
Parent: Template

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.

Methods

Public Class methods

Creates a new splitter.

klass:database class
bstream:input stream. It must be a BufferedInputStream object.

[Source]

     # File lib/bio/io/flatfile/splitter.rb, line 214
214:         def initialize(klass, bstream)
215:           super(klass, bstream)
216:           self.flag_to_fetch_header = true
217:         end

Public Instance methods

get an entry and return the entry as a string

[Source]

     # File lib/bio/io/flatfile/splitter.rb, line 225
225:         def get_entry
226:           if e = get_parsed_entry then
227:             entry
228:           else
229:             e
230:           end
231:         end

get an entry and return the entry as a data class object

[Source]

     # File lib/bio/io/flatfile/splitter.rb, line 234
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

rewinds the stream

[Source]

     # File lib/bio/io/flatfile/splitter.rb, line 275
275:         def rewind
276:           ret = super
277:           self.flag_to_fetch_header = true
278:           ret
279:         end

do nothing

[Source]

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

[Validate]