Class: IknowParams::Serializer::Integer
- Inherits:
-
IknowParams::Serializer
- Object
- IknowParams::Serializer
- IknowParams::Serializer::Integer
- Defined in:
- lib/iknow_params/serializer.rb
Instance Attribute Summary
Attributes inherited from IknowParams::Serializer
Instance Method Summary collapse
-
#initialize ⇒ Integer
constructor
A new instance of Integer.
-
#load(str_or_num) ⇒ Object
JSON only supports floats, so we have to accept a value which may have already been parsed into a Ruby Float or Integer.
Methods inherited from IknowParams::Serializer
#dump, for, for!, json_value?, #matches_type!, #matches_type?, singleton
Constructor Details
#initialize ⇒ Integer
Returns a new instance of Integer.
105 106 107 |
# File 'lib/iknow_params/serializer.rb', line 105 def initialize super(::Integer) end |
Instance Method Details
#load(str_or_num) ⇒ Object
JSON only supports floats, so we have to accept a value which may have already been parsed into a Ruby Float or Integer.
111 112 113 114 115 116 |
# File 'lib/iknow_params/serializer.rb', line 111 def load(str_or_num) raise LoadError.new("Invalid integer: #{str_or_num}") unless [::String, ::Integer].any? { |t| str_or_num.is_a?(t) } Integer(str_or_num) rescue ArgumentError => e raise LoadError.new(e.) end |