Class: Humidifier::Props::BooleanProp
- Defined in:
- lib/humidifier/props/boolean_prop.rb
Overview
A boolean property
Constant Summary
Constants inherited from Base
Humidifier::Props::Base::WHITELIST
Instance Attribute Summary
Attributes inherited from Base
#key, #name, #spec, #substructs
Instance Method Summary collapse
-
#convert(value) ⇒ Object
converts the value through ‘value == ’true’‘ unless it is valid.
-
#valid?(value) ⇒ Boolean
true if it is a boolean.
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 ‘value == ’true’‘ unless it is valid
8 9 10 11 12 13 14 15 |
# File 'lib/humidifier/props/boolean_prop.rb', line 8 def convert(value) if valid?(value) || !%w[true false].include?(value) value else puts "WARNING: Property #{name} should be a boolean, not a string" value == 'true' end end |
#valid?(value) ⇒ Boolean
true if it is a boolean
18 19 20 21 22 |
# File 'lib/humidifier/props/boolean_prop.rb', line 18 def valid?(value) return true if whitelisted_value?(value) value.is_a?(TrueClass) || value.is_a?(FalseClass) end |