Class: IknowParams::Serializer::Boolean

Inherits:
IknowParams::Serializer show all
Defined in:
lib/iknow_params/serializer.rb

Instance Attribute Summary

Attributes inherited from IknowParams::Serializer

#clazz

Instance Method Summary collapse

Methods inherited from IknowParams::Serializer

#dump, for, for!, json_value?, #matches_type!, singleton

Constructor Details

#initializeBoolean

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

Returns:



154
155
156
# File 'lib/iknow_params/serializer.rb', line 154

def matches_type?(val)
  [true, false].include?(val)
end