Class: Insnergy::Power
- Inherits:
-
Object
- Object
- Insnergy::Power
- Defined in:
- lib/insnergy-api-ruby-client.rb
Instance Attribute Summary collapse
-
#alias ⇒ Object
readonly
Returns the value of attribute alias.
-
#device_type_pointer ⇒ Object
readonly
Returns the value of attribute device_type_pointer.
-
#month_total_power_value ⇒ Object
readonly
Returns the value of attribute month_total_power_value.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #device_is_multiple_hole(opts) ⇒ Object
- #device_is_single_hole(opts) ⇒ Object
-
#initialize(opts = {}) ⇒ Power
constructor
A new instance of Power.
Constructor Details
#initialize(opts = {}) ⇒ Power
Returns a new instance of Power.
67 68 69 70 71 72 73 74 75 |
# File 'lib/insnergy-api-ruby-client.rb', line 67 def initialize(opts = {}) @device_type_pointer = opts['devices'][0].keys.include? 'sub_dev_id' case device_type_pointer when true device_is_multiple_hole(opts) when false device_is_single_hole(opts) end end |
Instance Attribute Details
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
65 66 67 |
# File 'lib/insnergy-api-ruby-client.rb', line 65 def alias @alias end |
#device_type_pointer ⇒ Object (readonly)
Returns the value of attribute device_type_pointer.
65 66 67 |
# File 'lib/insnergy-api-ruby-client.rb', line 65 def device_type_pointer @device_type_pointer end |
#month_total_power_value ⇒ Object (readonly)
Returns the value of attribute month_total_power_value.
65 66 67 |
# File 'lib/insnergy-api-ruby-client.rb', line 65 def month_total_power_value @month_total_power_value end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
65 66 67 |
# File 'lib/insnergy-api-ruby-client.rb', line 65 def type @type end |
Instance Method Details
#device_is_multiple_hole(opts) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/insnergy-api-ruby-client.rb', line 77 def device_is_multiple_hole(opts) @type = "multiple hole" holes = opts['devices'][0]['data'][0]['value'].split(';') names = opts['devices'][0]['sub_alias'].to_s.split(';') for i in 1..holes.size self.class.send(:attr_reader, "hole_#{i}_power_value", "hole_#{i}_alias") instance_variable_set("@hole_#{i}_power_value", holes[i - 1].to_f) instance_variable_set("@hole_#{i}_alias", names[i - 1].split('|')[1].split(':')[1]) end end |
#device_is_single_hole(opts) ⇒ Object
88 89 90 91 92 |
# File 'lib/insnergy-api-ruby-client.rb', line 88 def device_is_single_hole(opts) @type = "single hole" @power_value = opts['devices'][0]['data'][0]['value'].to_f @alias = opts['devices'][0]['alias'] end |