Class: EGauge::Register

Inherits:
Object
  • Object
show all
Defined in:
lib/egauge/register.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/egauge/register.rb', line 6

def index
  @index
end

#labelObject

Returns the value of attribute label.



6
7
8
# File 'lib/egauge/register.rb', line 6

def label
  @label
end

#type_codeObject

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

#countObject



41
42
43
# File 'lib/egauge/register.rb', line 41

def count
  @data.num_rows
end

#each_rowObject

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_aObject

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