Sha256: 9d997950e6745e2051dc508740202c001db7269c04d1bfcc8cef9c9b32e72c0a
Contents?: true
Size: 712 Bytes
Versions: 2
Compression:
Stored size: 712 Bytes
Contents
class Eco::API::Common::People::DefaultParsers::NumericParser < Eco::API::Common::Loaders::Parser attribute :number def parser(value, _deps) parse_number(value) end def serializer(value, _deps) value.is_a?(Array) ? value.map(&:to_s) : value.to_s end private def parse_number(value) return value.map {|val| parse_number(val)}.compact if value.is_a?(Enumerable) return nil if value.nil? value = value.to_s.strip return nil if value.empty? return nil unless number?(value) value.to_f rescue ArgumentError, TypeError nil end def number?(value) true if Float(value) rescue ArgumentError, TypeError false end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
eco-helpers-2.7.1 | lib/eco/api/common/people/default_parsers/numeric_parser.rb |
eco-helpers-2.7.0 | lib/eco/api/common/people/default_parsers/numeric_parser.rb |