class FunWithJsonApi::Attributes::DecimalAttribute
Public Instance Methods
decode(value)
click to toggle source
# File lib/fun_with_json_api/attributes/decimal_attribute.rb, line 4 def decode(value) if value unless value.to_s =~ /[0-9]+(\.[0-9]+)?/ raise build_invalid_attribute_error(value) end BigDecimal(value.to_s) end end
Protected Instance Methods
build_invalid_attribute_error(value)
click to toggle source
# File lib/fun_with_json_api/attributes/decimal_attribute.rb, line 15 def build_invalid_attribute_error(value) payload = ExceptionPayload.new payload.detail = I18n.t('fun_with_json_api.exceptions.invalid_decimal_attribute') payload.pointer = "/data/attributes/#{name}" Exceptions::InvalidAttribute.new("Unable to parse decimal: #{value.inspect}", payload) end