Sha256: 4b8185f54e4706d81fd97bd04a8d4ccea329525f34f56c763b6749d2c36b664e
Contents?: true
Size: 1.79 KB
Versions: 6
Compression:
Stored size: 1.79 KB
Contents
require 'omf_oml' require 'omf_oml/schema' require 'omf_oml/tuple' module OMF::OML # This class represents a single vector from an OML measurement stream. # It provides various methods to access the vectors elements. # # NOTE: Do not store the vector itself, but make a copy as the instance may be # reused over various rows by the sender. # class OmlTuple < Tuple # Return the elements of the vector as an array # def to_a(include_index_ts = false) # res = [] # r = @raw # if include_index_ts # res << @vprocs[:oml_ts].call(r) # res << @vprocs[:oml_seq_no].call(r) # end # @schema.each do |col| # res << @vprocs[col[:name]].call(r) # end # res # end def ts @raw[0].to_f end def seq_no @raw[1].to_i end # Note: This method assumes that the first two elements in each OML tuple, # 'oml_ts' and 'oml_seq_no' are not defined in the associated schema. # def process_schema(schema) i = 0 @vprocs = {} schema.each_column do |col| # name = col[:name] || raise("Ill-formed schema '#{schema}'") type = col[:type] || raise("Ill-formed schema '#{schema}'") j = i + 2; # need to create a locally scoped variable for the following lambdas @vprocs[name] = @vprocs[i] = case type when :string lambda do |r| r[j] end when :float lambda do |r| r[j].to_f end when :integer lambda do |r| r[j].to_i end else raise "Unrecognized OML type '#{type}' (#{col.inspect})" end i += 1 end @vprocs[:oml_ts] = lambda do |r| r[0].to_f end @vprocs[:oml_seq_no] = lambda do |r| r[1].to_i end end end # OmlTuple end # OMF::OML
Version data entries
6 entries across 6 versions & 1 rubygems