Class: Bio::FlatFile::Splitter::Default
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)
-
- (Object) delimiter
(String) delimiter indicates the end of a entry.
-
- (Object) delimiter_overrun
(Integer) excess read data size included in delimiter.
-
- (Object) header
(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, #parsed_entry
Instance Method Summary (collapse)
-
- (Object) get_entry
gets a entry.
-
- (Default) initialize(klass, bstream)
constructor
Creates a new splitter.
-
- (Object) skip_leader
Skips leader of the entry.
Methods inherited from Template
Constructor Details
- (Default) initialize(klass, bstream)
Creates a new splitter.
klass |
database class |
bstream |
input stream. It must be a BufferedInputStream object. |
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/bio/io/flatfile/splitter.rb', line 128 def initialize(klass, bstream) super(klass, bstream) @delimiter = klass::DELIMITER rescue nil @header = klass::FLATFILE_HEADER rescue nil # for specific classes' benefit unless header if (defined?(Bio::GenBank) and klass == Bio::GenBank) or (defined?(Bio::GenPept) and klass == Bio::GenPept) @header = 'LOCUS ' end end @delimiter_overrun = klass::DELIMITER_OVERRUN rescue nil end |
Instance Attribute Details
- (Object) delimiter
(String) delimiter indicates the end of a entry.
144 145 146 |
# File 'lib/bio/io/flatfile/splitter.rb', line 144 def delimiter @delimiter end |
- (Object) delimiter_overrun
(Integer) excess read data size included in delimiter.
150 151 152 |
# File 'lib/bio/io/flatfile/splitter.rb', line 150 def delimiter_overrun @delimiter_overrun end |
- (Object) header
(String) start of a entry, located on head of a line.
147 148 149 |
# File 'lib/bio/io/flatfile/splitter.rb', line 147 def header @header end |
Instance Method Details
- (Object) get_entry
gets a entry
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/bio/io/flatfile/splitter.rb', line 180 def get_entry p0 = stream_pos() 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 = stream_pos() self.entry_start_pos = p0 self.entry = e self.entry_ended_pos = p1 return entry end |
- (Object) skip_leader
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.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/bio/io/flatfile/splitter.rb', line 158 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 |