Class: Bio::FlatFile::Splitter::LineOriented
- Defined in:
- lib/bio/io/flatfile/splitter.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from Template
#entry, #entry_ended_pos, #entry_pos_flag, #entry_start_pos, #parsed_entry
Instance Method Summary collapse
-
#get_entry ⇒ Object
get an entry and return the entry as a string.
-
#get_parsed_entry ⇒ Object
get an entry and return the entry as a data class object.
-
#initialize(klass, bstream) ⇒ LineOriented
constructor
Creates a new splitter.
-
#rewind ⇒ Object
rewinds the stream.
-
#skip_leader ⇒ Object
do nothing.
Constructor Details
#initialize(klass, bstream) ⇒ LineOriented
Creates a new splitter.
- klass
-
database class
- bstream
-
input stream. It must be a BufferedInputStream object.
214 215 216 217 |
# File 'lib/bio/io/flatfile/splitter.rb', line 214 def initialize(klass, bstream) super(klass, bstream) self.flag_to_fetch_header = true end |
Instance Method Details
#get_entry ⇒ Object
get an entry and return the entry as a string
225 226 227 228 229 230 231 |
# 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 ⇒ Object
get an entry and return the entry as a data class object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# 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 ⇒ Object
rewinds the stream
275 276 277 278 279 |
# File 'lib/bio/io/flatfile/splitter.rb', line 275 def rewind ret = super self.flag_to_fetch_header = true ret end |
#skip_leader ⇒ Object
do nothing
220 221 222 |
# File 'lib/bio/io/flatfile/splitter.rb', line 220 def skip_leader nil end |