Class: MFi::MPowerReading
- Inherits:
-
Object
- Object
- MFi::MPowerReading
- Defined in:
- lib/mpower.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#enable ⇒ Object
Returns the value of attribute enable.
-
#energy ⇒ Object
Returns the value of attribute energy.
-
#port ⇒ Object
Returns the value of attribute port.
-
#power ⇒ Object
Returns the value of attribute power.
-
#powerfactor ⇒ Object
Returns the value of attribute powerfactor.
-
#relay ⇒ Object
Returns the value of attribute relay.
-
#voltage ⇒ Object
Returns the value of attribute voltage.
Instance Method Summary collapse
- #fmt(v) ⇒ Object
-
#initialize(port, opts) ⇒ MPowerReading
constructor
A new instance of MPowerReading.
- #to_s ⇒ Object
Constructor Details
#initialize(port, opts) ⇒ MPowerReading
Returns a new instance of MPowerReading.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mpower.rb', line 7 def initialize port, opts @port = port @enable = opts["enable"].to_i @relay = opts["relay"].to_i @power = opts["power"].to_f @energy = opts["energy"].to_f @current = opts["current"].to_f @voltage = opts["voltage"].to_f @powerfactor = opts["powerfactor"].to_f end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
5 6 7 |
# File 'lib/mpower.rb', line 5 def current @current end |
#enable ⇒ Object
Returns the value of attribute enable.
5 6 7 |
# File 'lib/mpower.rb', line 5 def enable @enable end |
#energy ⇒ Object
Returns the value of attribute energy.
5 6 7 |
# File 'lib/mpower.rb', line 5 def energy @energy end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/mpower.rb', line 5 def port @port end |
#power ⇒ Object
Returns the value of attribute power.
5 6 7 |
# File 'lib/mpower.rb', line 5 def power @power end |
#powerfactor ⇒ Object
Returns the value of attribute powerfactor.
5 6 7 |
# File 'lib/mpower.rb', line 5 def powerfactor @powerfactor end |
#relay ⇒ Object
Returns the value of attribute relay.
5 6 7 |
# File 'lib/mpower.rb', line 5 def relay @relay end |
#voltage ⇒ Object
Returns the value of attribute voltage.
5 6 7 |
# File 'lib/mpower.rb', line 5 def voltage @voltage end |
Instance Method Details
#fmt(v) ⇒ Object
22 23 24 |
# File 'lib/mpower.rb', line 22 def fmt v "%5.1f" % v end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/mpower.rb', line 18 def to_s "Port #{@port}: #{fmt(@power)}W (#{fmt(@powerfactor)}pf #{fmt(@current)}A #{fmt(@voltage)}V)" end |