Module: UnitMeasurements::Math
- Included in:
- Measurement
- Defined in:
- lib/unit_measurements/math.rb
Overview
The UnitMeasurements::Math
mixin module provides methods for performing mathematical functions on the measurement.
This module is included in the Measurement
class to allow mathematical functions on the measurement.
Instance Method Summary collapse
-
#abs ⇒ Measurement
Returns absolute value of the measurement quantity.
-
#cbrt ⇒ Measurement
Returns cube root of the measurement quantity.
-
#ceil(ndigits = 0) ⇒ Measurement
Returns ceiled quantity of the measurement.
-
#floor(ndigits = 0) ⇒ Measurement
Returns floored quantity of the measurement.
-
#round(ndigits = 0) ⇒ Measurement
Rounds quantity of the measurement.
-
#sqrt ⇒ Measurement
Returns square root of the measurement quantity.
Instance Method Details
#abs ⇒ Measurement
Returns absolute value of the measurement quantity.
47 48 49 |
# File 'lib/unit_measurements/math.rb', line 47 def abs self.class.new(quantity.abs, unit) end |
#cbrt ⇒ Measurement
Returns cube root of the measurement quantity.
116 117 118 |
# File 'lib/unit_measurements/math.rb', line 116 def cbrt self.class.new((quantity ** Rational(1, 3)), unit) end |
#ceil(ndigits = 0) ⇒ Measurement
Returns ceiled quantity of the measurement. If ndigits
is not specified, quantity is rounded to next higher Integer
.
87 88 89 |
# File 'lib/unit_measurements/math.rb', line 87 def ceil(ndigits = 0) self.class.new(quantity.ceil(ndigits), unit) end |
#floor(ndigits = 0) ⇒ Measurement
Returns floored quantity of the measurement. If ndigits
is not specified, quantity is rounded to next lower Integer
.
67 68 69 |
# File 'lib/unit_measurements/math.rb', line 67 def floor(ndigits = 0) self.class.new(quantity.floor(ndigits), unit) end |
#round(ndigits = 0) ⇒ Measurement
Rounds quantity of the measurement. If ndigits
is not specified, quantity is rounded to Integer
.
32 33 34 |
# File 'lib/unit_measurements/math.rb', line 32 def round(ndigits = 0) self.class.new(quantity.round(ndigits), unit) end |
#sqrt ⇒ Measurement
Returns square root of the measurement quantity.
101 102 103 |
# File 'lib/unit_measurements/math.rb', line 101 def sqrt self.class.new((quantity ** Rational(1, 2)), unit) end |