Class: IknowParams::Serializer::Boolean
- Inherits:
-
IknowParams::Serializer
- Object
- IknowParams::Serializer
- IknowParams::Serializer::Boolean
- Defined in:
- lib/iknow_params/serializer.rb
Instance Attribute Summary
Attributes inherited from IknowParams::Serializer
Instance Method Summary collapse
-
#initialize ⇒ Boolean
constructor
A new instance of Boolean.
- #load(str) ⇒ Object
- #matches_type?(val) ⇒ Boolean
Methods inherited from IknowParams::Serializer
#dump, for, for!, json_value?, #matches_type!, singleton
Constructor Details
#initialize ⇒ Boolean
Returns a new instance of Boolean.
138 139 140 |
# File 'lib/iknow_params/serializer.rb', line 138 def initialize super(nil) end |
Instance Method Details
#load(str) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/iknow_params/serializer.rb', line 142 def load(str) str = str.downcase if str.is_a?(::String) if ['false', 'no', 'off', false, '0', 0].include?(str) false elsif ['true', 'yes', 'on', true, '1', 1].include?(str) true else raise LoadError.new("Invalid boolean: #{str.inspect}") end end |
#matches_type?(val) ⇒ Boolean
154 155 156 |
# File 'lib/iknow_params/serializer.rb', line 154 def matches_type?(val) [true, false].include?(val) end |