Class: Humidifier::Props::BooleanProp

Inherits:
Base
  • Object
show all
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

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

Returns:

  • (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