class Mspire::Mzml::IOIndex
an index that retrieves its objects on the fly by index from the IO
object.
Attributes
byte_index[R]
io[R]
link[RW]
hash of relevant hashes and objects for linking
Public Class Methods
new(io, byte_index, link)
click to toggle source
byte_index
will typically be an Mspire::Mzml::Index
object.
link will have the following keys:
:ref_hash :data_processing_hash :(<sample>|<chromatogram>)_default_data_processing
may have:
:source_file_hash
# File lib/mspire/mzml/io_index.rb, line 31 def initialize(io, byte_index, link) @io, @byte_index, @link = io, byte_index, link @object_class = Mspire::Mzml.const_get(@byte_index.name.to_s.capitalize) @closetag_regexp = %r{</#{name}>} end
Public Instance Methods
[](index)
click to toggle source
# File lib/mspire/mzml/io_index.rb, line 48 def [](index) @object_class.from_xml(fetch_xml_node(index), @link) end
each(&block)
click to toggle source
# File lib/mspire/mzml/io_index.rb, line 41 def each(&block) return to_enum(__method__) unless block (0...byte_index.size).each do |int| block.call(self[int]) end end
fetch_xml_node(index)
click to toggle source
# File lib/mspire/mzml/io_index.rb, line 74 def fetch_xml_node(index) xml_node_from_start_byte(byte_index[index]) end
get_xml_string(start_byte)
click to toggle source
gets the data string through to last element
# File lib/mspire/mzml/io_index.rb, line 58 def get_xml_string(start_byte) @io.seek(start_byte) data = "" @io.each_line do |line| data << line break if @closetag_regexp.match(line) end data end
length()
click to toggle source
# File lib/mspire/mzml/io_index.rb, line 52 def length @byte_index.length end
Also aliased as: size
name()
click to toggle source
# File lib/mspire/mzml/io_index.rb, line 37 def name @byte_index.name end
xml_node_from_start_byte(start_byte)
click to toggle source
# File lib/mspire/mzml/io_index.rb, line 68 def xml_node_from_start_byte(start_byte) # consider passing in @encoding from upstream object (as second nil): xml = get_xml_string(start_byte) Nokogiri::XML.parse(xml, nil, nil, Parser::NOBLANKS).root end