Class: EGauge::Register
- Inherits:
-
Object
- Object
- EGauge::Register
- Defined in:
- lib/egauge/register.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#label ⇒ Object
Returns the value of attribute label.
-
#type_code ⇒ Object
Returns the value of attribute type_code.
Instance Method Summary collapse
- #count ⇒ Object
-
#each_row ⇒ Object
Run each value in this register, yielding |timestamp, value| for each.
-
#initialize(data, index, def_node) ⇒ Register
constructor
A new instance of Register.
-
#to_a ⇒ Object
Return results as a 2D array, like so: [ [timestamp1, val1], [timestamp2, val2], … ].
Constructor Details
#initialize(data, index, def_node) ⇒ Register
Returns a new instance of Register.
8 9 10 11 12 13 14 |
# File 'lib/egauge/register.rb', line 8 def initialize(data, index, def_node) @data = data @index = index @label = def_node.text @type_code = def_node['t'] end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
6 7 8 |
# File 'lib/egauge/register.rb', line 6 def index @index end |
#label ⇒ Object
Returns the value of attribute label.
6 7 8 |
# File 'lib/egauge/register.rb', line 6 def label @label end |
#type_code ⇒ Object
Returns the value of attribute type_code.
6 7 8 |
# File 'lib/egauge/register.rb', line 6 def type_code @type_code end |
Instance Method Details
#count ⇒ Object
41 42 43 |
# File 'lib/egauge/register.rb', line 41 def count @data.num_rows end |
#each_row ⇒ Object
Run each value in this register, yielding |timestamp, value| for each
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/egauge/register.rb', line 17 def each_row @data.xml.group.elements.each do |chunk| # Set up for running this data chunk - prep timestamp and increment step from source xml ts = EGauge::parse_time(chunk['time_stamp']) step = chunk['time_delta'].to_i # Run each row in the chunk, and yield our results (chunk / './r').each do |row| val = (row / './c')[@index].text.to_i yield ts, val ts += step end end end |
#to_a ⇒ Object
Return results as a 2D array, like so: [ [timestamp1, val1], [timestamp2, val2], … ]
33 34 35 36 37 38 39 |
# File 'lib/egauge/register.rb', line 33 def to_a res = [] each_row do |ts, val| res << [ts, val] end res end |