Class: Humidifier::Props::DoubleProp
- Defined in:
- lib/humidifier/props/double_prop.rb
Overview
A double property
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#key, #name, #spec, #substructs
Instance Method Summary collapse
-
#convert(value) ⇒ Object
converts the value through #to_f unless it is valid.
-
#valid?(value) ⇒ Boolean
true if it is whitelisted, an Integer, or a Float.
Methods inherited from Base
#documentation, #initialize, #required?, #to_cf, #update_type, #whitelisted_value?
Constructor Details
This class inherits a constructor from Humidifier::Props::Base
Instance Method Details
#convert(value) ⇒ Object
converts the value through #to_f unless it is valid
6 7 8 9 10 11 12 13 |
# File 'lib/humidifier/props/double_prop.rb', line 6 def convert(value) if valid?(value) || !value.respond_to?(:to_f) value else puts "WARNING: Property #{name} should be a double" value.to_f end end |
#valid?(value) ⇒ Boolean
true if it is whitelisted, an Integer, or a Float
16 17 18 |
# File 'lib/humidifier/props/double_prop.rb', line 16 def valid?(value) whitelisted_value?(value) || value.is_a?(Integer) || value.is_a?(Float) end |