Class: Tempura::Temperature
- Inherits:
-
Object
- Object
- Tempura::Temperature
- Includes:
- Comparable
- Defined in:
- lib/tempura/temperature.rb
Overview
Parent class of all Temperature objects in Tempura, inherited by Tempura::Celsius, etc.
Instance Method Summary collapse
-
#*(temp) ⇒ Object
Multiplies by
Numeric. -
#+(temp) ⇒ Object
Adds a
Temperatureof any scale, or a numeric representation of the same scale as the receiver. -
#-(temp) ⇒ Object
Subtracts a
Temperatureof any scale, or a numeric representation of the same scale as the receiver. -
#/(temp) ⇒ Object
Divides by
Numeric. -
#<=>(temp) ⇒ Object
Compares against a
Temperatureof any scale, or a numeric representation of the same scale as the receiver. -
#initialize(temp) ⇒ Temperature
constructor
A new instance of Temperature.
-
#to ⇒ Object
Returns Conversion for the receiver, which recieves the name of the scale to convert to.
-
#to_d ⇒ Object
BigDecimal representation of receiver.
-
#to_f ⇒ Object
Float representation of receiver.
-
#to_i ⇒ Object
Integer representation of receiver.
Constructor Details
#initialize(temp) ⇒ Temperature
Returns a new instance of Temperature.
7 8 9 10 11 12 13 |
# File 'lib/tempura/temperature.rb', line 7 def initialize(temp) if temp.is_a?(Tempura::Temperature) @common = temp.send(:common) else @common = to_common(temp) end end |
Instance Method Details
#*(temp) ⇒ Object
Multiplies by Numeric.
53 54 55 56 57 58 |
# File 'lib/tempura/temperature.rb', line 53 def *(temp) if temp.is_a?(Tempura::Temperature) raise ArgumentError, "cannot multiply by a Tempura::Temperature, only a Numeric" end self.class.new(in_native * temp) end |
#+(temp) ⇒ Object
Adds a Temperature of any scale, or a numeric representation of the same scale as the receiver.
36 37 38 |
# File 'lib/tempura/temperature.rb', line 36 def +(temp) self.class.new(in_native + numericalize(temp)) end |
#-(temp) ⇒ Object
Subtracts a Temperature of any scale, or a numeric representation of the same scale as the receiver.
29 30 31 |
# File 'lib/tempura/temperature.rb', line 29 def -(temp) self.class.new(in_native - numericalize(temp)) end |
#/(temp) ⇒ Object
Divides by Numeric.
43 44 45 46 47 48 |
# File 'lib/tempura/temperature.rb', line 43 def /(temp) if temp.is_a?(Tempura::Temperature) raise ArgumentError, "cannot divide by a Tempura::Temperature, only a Numeric" end self.class.new(in_native.div(temp)) end |
#<=>(temp) ⇒ Object
Compares against a Temperature of any scale, or a numeric representation of the same scale as the receiver.
18 19 20 21 22 23 24 |
# File 'lib/tempura/temperature.rb', line 18 def <=>(temp) if temp.is_a?(Tempura::Temperature) @common <=> temp.send(:common) else @common <=> to_common(temp) end end |
#to ⇒ Object
Returns Conversion for the receiver, which recieves the name of the scale to convert to. E.g.,
c = Tempura::Celsius.new(100)
c.to.fahrenheit #=> <Tempura::Fahrenheit ...
65 66 67 |
# File 'lib/tempura/temperature.rb', line 65 def to Tempura::Conversion.new(self) end |
#to_d ⇒ Object
BigDecimal representation of receiver
80 81 82 |
# File 'lib/tempura/temperature.rb', line 80 def to_d in_native end |
#to_f ⇒ Object
Float representation of receiver
70 71 72 |
# File 'lib/tempura/temperature.rb', line 70 def to_f in_native.to_f end |
#to_i ⇒ Object
Integer representation of receiver
75 76 77 |
# File 'lib/tempura/temperature.rb', line 75 def to_i in_native.to_i end |