lib/pulse_meter/mixins/utils.rb
# 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.
# @param options [Hash] hash to be looked at
# @param key [Object] hash key
# @param from [Float] lower bound
# @param to [Float] upper bound
# @raise [ArgumentError] unless value is float within given range
# @return [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.
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 .
def assert_ranged_float!(options, key, from, to)
        f = options[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
        options[key] = f
      end
def assert_ranged_float! ( options , key , from , to ) f = options [ 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 options [ key ] = f end
Ensures that hash value specified by key is can be converted to float
and it is within given range.
Ensures that hash value specified by key is can be converted to float and it is within given range .
None
Float
[ArgumentError] unless value is float within given range
[ ArgumentError ] unless value is float within given range
options
hash to be looked at
hash to be looked at
key
None
from
None
to
None