Class: ParamsTransformer::ValueParser::Integer

Inherits:
ParamsTransformer::ValueParser show all
Defined in:
lib/params_transformer/value_parser/integer.rb

Constant Summary collapse

REGEX =
/(\d|[.])/

Instance Attribute Summary

Attributes inherited from ParamsTransformer::ValueParser

#input_value

Instance Method Summary collapse

Methods inherited from ParamsTransformer::ValueParser

#after_init, #initialize

Constructor Details

This class inherits a constructor from ParamsTransformer::ValueParser

Instance Method Details

#parseObject



6
7
8
9
10
11
# File 'lib/params_transformer/value_parser/integer.rb', line 6

def parse
  return 0 unless input_value.present?
  return input_value if input_value.is_a?(Fixnum)
  return input_value.to_i if input_value.is_a?(Float)
  input_value.scan(REGEX).join.try(:to_i)
end