Class: Mspire::Mzml::IOIndex
- Inherits:
-
Object
- Object
- Mspire::Mzml::IOIndex
- Includes:
- Enumerable
- Defined in:
- lib/mspire/mzml/io_index.rb
Overview
an index that retrieves its objects on the fly by index from the IO object.
Instance Attribute Summary collapse
-
#byte_index ⇒ Object
readonly
Returns the value of attribute byte_index.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#link ⇒ Object
hash of relevant hashes and objects for linking.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each(&block) ⇒ Object
- #fetch_xml_node(index) ⇒ Object
-
#get_xml_string(start_byte) ⇒ Object
gets the data string through to last element.
-
#initialize(io, byte_index, link) ⇒ IOIndex
constructor
byte_index will typically be an Mspire::Mzml::Index object.
- #length ⇒ Object (also: #size)
- #name ⇒ Object
- #xml_node_from_start_byte(start_byte) ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize(io, byte_index, link) ⇒ IOIndex
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
31 32 33 34 35 |
# 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 |
Instance Attribute Details
#byte_index ⇒ Object (readonly)
Returns the value of attribute byte_index.
14 15 16 |
# File 'lib/mspire/mzml/io_index.rb', line 14 def byte_index @byte_index end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
12 13 14 |
# File 'lib/mspire/mzml/io_index.rb', line 12 def io @io end |
#link ⇒ Object
hash of relevant hashes and objects for linking
17 18 19 |
# File 'lib/mspire/mzml/io_index.rb', line 17 def link @link end |
Instance Method Details
#[](index) ⇒ Object
48 49 50 |
# File 'lib/mspire/mzml/io_index.rb', line 48 def [](index) @object_class.from_xml(fetch_xml_node(index), @link) end |
#each(&block) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/mspire/mzml/io_index.rb', line 41 def each(&block) return enum_for(__method__) unless block (0...byte_index.size).each do |int| block.call(self[int]) end end |
#fetch_xml_node(index) ⇒ Object
73 74 75 |
# File 'lib/mspire/mzml/io_index.rb', line 73 def fetch_xml_node(index) xml_node_from_start_byte(byte_index[index]) end |
#get_xml_string(start_byte) ⇒ Object
gets the data string through to last element
58 59 60 61 62 63 64 65 66 |
# 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 ⇒ Object Also known as: size
52 53 54 |
# File 'lib/mspire/mzml/io_index.rb', line 52 def length @byte_index.length end |
#name ⇒ Object
37 38 39 |
# File 'lib/mspire/mzml/io_index.rb', line 37 def name @byte_index.name end |