Class: Superstore::Types::BooleanType
- Defined in:
- lib/superstore/types/boolean_type.rb
Constant Summary collapse
- TRUE_VALS =
[true, 'true', '1']
- FALSE_VALS =
[false, 'false', '0', '', nil]
- VALID_VALS =
TRUE_VALS + FALSE_VALS
Instance Attribute Summary
Attributes inherited from BaseType
Instance Method Summary collapse
Methods inherited from BaseType
#default, #initialize, #typecast
Constructor Details
This class inherits a constructor from Superstore::Types::BaseType
Instance Method Details
#decode(str) ⇒ Object
15 16 17 |
# File 'lib/superstore/types/boolean_type.rb', line 15 def decode(str) TRUE_VALS.include?(str) end |
#encode(bool) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/superstore/types/boolean_type.rb', line 8 def encode(bool) unless VALID_VALS.include?(bool) raise ArgumentError.new("#{bool.inspect} is not a Boolean") end TRUE_VALS.include?(bool) ? '1' : '0' end |