Method: PulseMeter::Mixins::Utils#assert_ranged_float!
- Defined in:
- lib/pulse_meter/mixins/utils.rb
#assert_ranged_float!(options, key, from, to) ⇒ Float
Ensures that hash value specified by key is can be converted to float and it is within given range. In case it can makes in-place conversion and returns the value.
55 56 57 58 59 60 61 62 |
# File 'lib/pulse_meter/mixins/utils.rb', line 55 def assert_ranged_float!(, key, from, to) f = [key] raise ArgumentError, "#{key} should be defined" unless f raise ArgumentError, "#{key} should be float" unless f.respond_to?(:to_f) f = f.to_f raise ArgumentError, "#{key} should be between #{from} and #{to}" unless f >= from && f <= to [key] = f end |