Module: PulseToolbox::Sensor::Mixins::Iterators

Included in:
PulseToolbox::Sensor::Manager
Defined in:
lib/pulse_toolbox/sensor/mixins/iterators.rb

Instance Method Summary collapse

Instance Method Details

#each_group {|group| ... } ⇒ Object

Executes block for each group

Yield Parameters:

  • group (Symbol)

    group name



8
9
10
11
12
# File 'lib/pulse_toolbox/sensor/mixins/iterators.rb', line 8

def each_group
  sensors_config.each_key do |group|
    yield(group)
  end
end

#each_group_with_title {|group, title, value_title| ... } ⇒ Object

Executes block for each group

Yield Parameters:

  • group (Symbol)

    group name

  • title (String)

    group title

  • value_title (String)

    group sensor value meaning



18
19
20
21
22
23
# File 'lib/pulse_toolbox/sensor/mixins/iterators.rb', line 18

def each_group_with_title
  sensors_config.each_key do |group_name|
    group = sensors_config[group_name]
    yield(group_name, group[:title] || group_name,  group[:values] || '')
  end
end

#each_sensor {|sensor| ... } ⇒ Object

Executes block for each sensor

Yield Parameters:

  • sensor (Symbol)

    sensor name



37
38
39
40
41
42
43
# File 'lib/pulse_toolbox/sensor/mixins/iterators.rb', line 37

def each_sensor
  each_group do |group|
    each_sensor_in_group(group) do |sensor|
      yield(sensor)
    end
  end
end

#each_sensor_in_group(group) {|sensor| ... } ⇒ Object

Executes block for each sensor in group

Parameters:

  • group (Symbol)

    group name

Yield Parameters:

  • sensor (Symbol)

    sensor name



28
29
30
31
32
33
# File 'lib/pulse_toolbox/sensor/mixins/iterators.rb', line 28

def each_sensor_in_group(group)
  sensors_config[group][:sensors].each_key do |name|
    sensor = get_sensor(group, name)
    yield(sensor)
  end
end

#sensorsArray<Symbol>

Returns all sensors from config

Returns:

  • (Array<Symbol>)

    sensors list



47
48
49
50
51
# File 'lib/pulse_toolbox/sensor/mixins/iterators.rb', line 47

def sensors
  list = []
  each_sensor {|s| list << s}
  list
end