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
Source
# File lib/bio/io/flatfile/splitter.rb 215 def initialize(klass, bstream) 216 super(klass, bstream) 217 self.flag_to_fetch_header = true 218 end
Creates a new splitter.
- klass
-
database class
- bstream
-
input stream. It must be a
BufferedInputStream
object.
Calls superclass method
Bio::FlatFile::Splitter::Template::new
Public Instance Methods
Source
# File lib/bio/io/flatfile/splitter.rb 226 def get_entry 227 if e = get_parsed_entry then 228 entry 229 else 230 e 231 end 232 end
get an entry and return the entry as a string
Source
# File lib/bio/io/flatfile/splitter.rb 235 def get_parsed_entry 236 p0 = stream_pos() 237 ent = @dbclass.new() 238 239 lines = [] 240 line_overrun = nil 241 242 if flag_to_fetch_header then 243 while line = stream.gets("\n") 244 unless ent.add_header_line(line) then 245 line_overrun = line 246 break 247 end 248 lines.push line 249 end 250 stream.ungets(line_overrun) if line_overrun 251 line_overrun = nil 252 self.flag_to_fetch_header = false 253 end 254 255 while line = stream.gets("\n") 256 unless ent.add_line(line) then 257 line_overrun = line 258 break 259 end 260 lines.push line 261 end 262 stream.ungets(line_overrun) if line_overrun 263 p1 = stream_pos() 264 265 return nil if lines.empty? 266 267 self.entry_start_pos = p0 268 self.entry = lines.join('') 269 self.parsed_entry = ent 270 self.entry_ended_pos = p1 271 272 return ent 273 end
get an entry and return the entry as a data class object
Source
# File lib/bio/io/flatfile/splitter.rb 276 def rewind 277 ret = super 278 self.flag_to_fetch_header = true 279 ret 280 end
rewinds the stream
Calls superclass method
Bio::FlatFile::Splitter::Template#rewind
Source
# File lib/bio/io/flatfile/splitter.rb 221 def skip_leader 222 nil 223 end
do nothing