Class: Bio::FlatFile::Splitter::Default
- Defined in:
- lib/bio/io/flatfile.rb
Overview
Default splitter. It sees following constants in the given class.
- DELIMITER
-
(String) delimiter indicates the end of a entry.
- FLATFILE_HEADER
-
(String) start of a entry, located on head of a line.
- DELIMITER_OVERRUN
-
(Integer) excess read size included in DELIMITER.
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
(String) delimiter indicates the end of a entry.
-
#delimiter_overrun ⇒ Object
(Integer) excess read data size included in delimiter.
-
#header ⇒ Object
(String) start of a entry, located on head of a line.
Attributes inherited from Template
#entry, #entry_ended_pos, #entry_pos_flag, #entry_start_pos
Instance Method Summary collapse
-
#get_entry ⇒ Object
gets a entry.
-
#initialize(klass, bstream) ⇒ Default
constructor
Creates a new splitter.
-
#skip_leader ⇒ Object
Skips leader of the entry.
Constructor Details
#initialize(klass, bstream) ⇒ Default
Creates a new splitter.
- klass
-
database class
- bstream
-
input stream. It must be a BufferedInputStream object.
284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/bio/io/flatfile.rb', line 284 def initialize(klass, bstream) @stream = bstream @delimiter = klass::DELIMITER rescue nil @header = klass::FLATFILE_HEADER rescue nil # for specific classes' benefit unless header if klass == Bio::GenBank or klass == Bio::GenPept @header = 'LOCUS ' end end @delimiter_overrun = klass::DELIMITER_OVERRUN rescue nil @entry_pos_flag = nil end |
Instance Attribute Details
#delimiter ⇒ Object
(String) delimiter indicates the end of a entry.
299 300 301 |
# File 'lib/bio/io/flatfile.rb', line 299 def delimiter @delimiter end |
#delimiter_overrun ⇒ Object
(Integer) excess read data size included in delimiter.
305 306 307 |
# File 'lib/bio/io/flatfile.rb', line 305 def delimiter_overrun @delimiter_overrun end |
#header ⇒ Object
(String) start of a entry, located on head of a line.
302 303 304 |
# File 'lib/bio/io/flatfile.rb', line 302 def header @header end |
Instance Method Details
#get_entry ⇒ Object
gets a entry
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/bio/io/flatfile.rb', line 335 def get_entry p0 = @entry_pos_flag ? @stream.pos : nil e = @stream.gets(@delimiter) if e and @delimiter_overrun then if e[-@delimiter.size, @delimiter.size ] == @delimiter then overrun = e[-@delimiter_overrun, @delimiter_overrun] e[-@delimiter_overrun, @delimiter_overrun] = '' @stream.ungets(overrun) end end p1 = @entry_pos_flag ? @stream.pos : nil @entry_start_pos = p0 @entry = e @entry_ended_pos = p1 @entry end |
#skip_leader ⇒ Object
Skips leader of the entry.
If @header is not nil, it reads till the contents of @header comes at the head of a line. If correct FLATFILE_HEADER is found, returns true. Otherwise, returns nil.
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/bio/io/flatfile.rb', line 313 def skip_leader if @header then data = '' while s = @stream.gets(@header) data << s if data.split(/[\r\n]+/)[-1] == @header then @stream.ungets(@header) return true end end # @header was not found. For safety, # pushes back data with removing white spaces in the head. data.sub(/\A\s+/, '') @stream.ungets(data) return nil else @stream.skip_spaces return nil end end |