class Bio::FlatFile::Splitter::Default
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.
Attributes
delimiter[RW]
(String) delimiter indicates the end of a entry.
delimiter_overrun[RW]
(Integer) excess read data size included in delimiter.
header[RW]
(String) start of a entry, located on head of a line.
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 128 def initialize(klass, bstream) 129 super(klass, bstream) 130 131 @delimiter = klass::DELIMITER rescue nil 132 @header = klass::FLATFILE_HEADER rescue nil 133 # for specific classes' benefit 134 unless header 135 if (defined?(Bio::GenBank) and klass == Bio::GenBank) or 136 (defined?(Bio::GenPept) and klass == Bio::GenPept) 137 @header = 'LOCUS ' 138 end 139 end 140 @delimiter_overrun = klass::DELIMITER_OVERRUN rescue nil 141 end
Public Instance Methods
get_entry()
click to toggle source
gets a entry
# File lib/bio/io/flatfile/splitter.rb 180 def get_entry 181 p0 = stream_pos() 182 e = stream.gets(@delimiter) 183 if e and @delimiter_overrun then 184 if e[-@delimiter.size, @delimiter.size ] == @delimiter then 185 overrun = e[-@delimiter_overrun, @delimiter_overrun] 186 e[-@delimiter_overrun, @delimiter_overrun] = '' 187 stream.ungets(overrun) 188 end 189 end 190 p1 = stream_pos() 191 self.entry_start_pos = p0 192 self.entry = e 193 self.entry_ended_pos = p1 194 return entry 195 end
skip_leader()
click to toggle source
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.
# File lib/bio/io/flatfile/splitter.rb 158 def skip_leader 159 if @header then 160 data = '' 161 while s = stream.gets(@header) 162 data << s 163 if data.split(/[\r\n]+/)[-1] == @header then 164 stream.ungets(@header) 165 return true 166 end 167 end 168 # @header was not found. For safety, 169 # pushes back data with removing white spaces in the head. 170 data.sub(/\A\s+/, '') 171 stream.ungets(data) 172 return nil 173 else 174 stream.skip_spaces 175 return nil 176 end 177 end