You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
since nil.to_i and ''.to_i coerce to 0, that might come in handy and would be nice to allow decanter to handle that rather than adding custom logic.
Suggested Solution
Also generally the IntegerParser may need to be refactored a bit but a simple update could be something like
apple_count, :integer, coerce: true
...
module Decanter
module Parser
class IntegerParser < ValueParser
REGEX = /(\d|[.]|[-])/
allow Integer
parser do |val, options|
raise Decanter::ParseError.new 'Expects a single value' if val.is_a? Array
return val&.to_i if options[:coerce] ==> something like this above the rest of the logic (nil does not implement `scan`)
next if (val.nil? || val === '')
val.is_a?(Float) ?
val.to_i :
val.scan(REGEX).join.try(:to_i)
end
end
end
end
Alternatives Considered / Existing Workarounds
Custom parser
Additional Context
N/A
The text was updated successfully, but these errors were encountered:
Feature Description
since
nil.to_i
and''.to_i
coerce to 0, that might come in handy and would be nice to allow decanter to handle that rather than adding custom logic.Suggested Solution
Also generally the IntegerParser may need to be refactored a bit but a simple update could be something like
Alternatives Considered / Existing Workarounds
Additional Context
The text was updated successfully, but these errors were encountered: