Class: DmmUtil::Reading
- Inherits:
-
Object
- Object
- DmmUtil::Reading
- Defined in:
- lib/dmm_util/reading.rb
Constant Summary collapse
- MULTIPLIER_MAP =
{ -12 => "p", -9 => "n", -6 => "u", -3 => "m", -2 => "c", -1 => "d", 0 => "", 1 => "D", 2 => "h", 3 => "k", 6 => "M", 9 => "G", 12 => "T" }
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(attrs) ⇒ Reading
constructor
A new instance of Reading.
- #scaled_value ⇒ Object
- #to_s ⇒ Object
- #ts ⇒ Object
- #unit ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Reading
Returns a new instance of Reading.
21 22 23 |
# File 'lib/dmm_util/reading.rb', line 21 def initialize(attrs) @raw = attrs end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
3 4 5 |
# File 'lib/dmm_util/reading.rb', line 3 def raw @raw end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 |
# File 'lib/dmm_util/reading.rb', line 58 def ==(other) value == other.value && unit == other.unit end |
#scaled_value ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dmm_util/reading.rb', line 37 def scaled_value decimals = @raw[:decimals] multiplier = @raw[:unit_multiplier] state = @raw[:state] if state == "NORMAL" val = "%.#{decimals}f" % (value / (10 ** multiplier)) elsif state == "OL_MINUS" val = "-OL" else val = state end [val, "#{MULTIPLIER_MAP[multiplier]}#{unit}"] end |
#to_s ⇒ Object
53 54 55 56 |
# File 'lib/dmm_util/reading.rb', line 53 def to_s sv = scaled_value "#{sv.first} #{sv.last}" end |
#ts ⇒ Object
25 26 27 |
# File 'lib/dmm_util/reading.rb', line 25 def ts raw[:ts] end |
#unit ⇒ Object
33 34 35 |
# File 'lib/dmm_util/reading.rb', line 33 def unit raw[:unit] end |
#value ⇒ Object
29 30 31 |
# File 'lib/dmm_util/reading.rb', line 29 def value raw[:value] end |