Class: Winker::Temperature
- Inherits:
-
Numeric
- Object
- Numeric
- Winker::Temperature
- Defined in:
- lib/winker/temperature.rb
Overview
TODO make temperture class for easy conversion between F and C this is not included in the project at this moment
Constant Summary collapse
- DEFAULT_SCALE =
"f"
Instance Attribute Summary collapse
-
#display_scale ⇒ Object
Returns the value of attribute display_scale.
-
#reading ⇒ Object
Returns the value of attribute reading.
-
#scale ⇒ Object
Returns the value of attribute scale.
Instance Method Summary collapse
-
#initialize(temp, scale = DEFAULT_SCALE, display_scale = DEFAULT_SCALE) ⇒ Temperature
constructor
A new instance of Temperature.
- #temp ⇒ Object
- #to_f ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(temp, scale = DEFAULT_SCALE, display_scale = DEFAULT_SCALE) ⇒ Temperature
Returns a new instance of Temperature.
8 9 10 11 12 |
# File 'lib/winker/temperature.rb', line 8 def initialize(temp, scale = DEFAULT_SCALE, display_scale = DEFAULT_SCALE) @reading = temp @scale = scale @display_scale = display_scale end |
Instance Attribute Details
#display_scale ⇒ Object
Returns the value of attribute display_scale.
6 7 8 |
# File 'lib/winker/temperature.rb', line 6 def display_scale @display_scale end |
#reading ⇒ Object
Returns the value of attribute reading.
6 7 8 |
# File 'lib/winker/temperature.rb', line 6 def reading @reading end |
#scale ⇒ Object
Returns the value of attribute scale.
6 7 8 |
# File 'lib/winker/temperature.rb', line 6 def scale @scale end |
Instance Method Details
#temp ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/winker/temperature.rb', line 26 def temp case when scale == display_scale return reading when scale == "f" && display_scale == "c" return (reading - 32) * 5.0 / 9 when scale == "c" && display_scale == "f" return (reading * 9.0 / 5) + 32 else raise "Doesn't support #{scale} temp scale" end end |
#to_f ⇒ Object
22 23 24 |
# File 'lib/winker/temperature.rb', line 22 def to_f temp.to_f end |
#to_i ⇒ Object
18 19 20 |
# File 'lib/winker/temperature.rb', line 18 def to_i temp.to_i end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/winker/temperature.rb', line 14 def to_s temp.to_s end |