Module: PulseToolbox::Sensor::Mixins::Iterators
- Included in:
- PulseToolbox::Sensor::Manager
- Defined in:
- lib/pulse_toolbox/sensor/mixins/iterators.rb
Instance Method Summary collapse
-
#each_group {|group| ... } ⇒ Object
Executes block for each group.
-
#each_group_with_title {|group, title, value_title| ... } ⇒ Object
Executes block for each group.
-
#each_sensor {|sensor| ... } ⇒ Object
Executes block for each sensor.
-
#each_sensor_in_group(group) {|sensor| ... } ⇒ Object
Executes block for each sensor in group.
-
#sensors ⇒ Array<Symbol>
Returns all sensors from config.
Instance Method Details
#each_group {|group| ... } ⇒ Object
Executes block for each group
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
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
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
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 |
#sensors ⇒ Array<Symbol>
Returns all sensors from config
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 |