Module: Rordash::NumericUtil
- Defined in:
- lib/rordash/numeric_util.rb
Defined Under Namespace
Modules: Unit
Class Method Summary collapse
- .convert_unit(value, from_unit:, to_unit:) ⇒ Object
- .convert_unit_sq(value, from_unit:, to_unit:) ⇒ Object
- .numeric?(value) ⇒ Boolean
Class Method Details
.convert_unit(value, from_unit:, to_unit:) ⇒ Object
17 18 19 |
# File 'lib/rordash/numeric_util.rb', line 17 def convert_unit(value, from_unit:, to_unit:) Measured::Length.new(value, from_unit).convert_to(to_unit).value.to_f end |
.convert_unit_sq(value, from_unit:, to_unit:) ⇒ Object
21 22 23 24 25 |
# File 'lib/rordash/numeric_util.rb', line 21 def convert_unit_sq(value, from_unit:, to_unit:) value = value.is_a?(String) ? BigDecimal(value) : value val = convert_unit(value, from_unit: from_unit, to_unit: to_unit) (val * val) / value end |
.numeric?(value) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/rordash/numeric_util.rb', line 11 def numeric?(value) !Float(value.to_s).nil? rescue StandardError false end |