Sha256: d9abac6307e173dc98119018f5252c00f6680a912d545251503a3722e6c39550
Contents?: true
Size: 1.32 KB
Versions: 18
Compression:
Stored size: 1.32 KB
Contents
module Frodo module Properties # Defines the Decimal Frodo type. class Decimal < Frodo::Property # Returns the property value, properly typecast # @return [BigDecimal,nil] def value if (@value.nil? || @value.empty?) && (!strict? && allows_nil?) nil else BigDecimal(@value) end end # Sets the property value # @params new_value something BigDecimal() can parse def value=(new_value) @value = if (new_value.nil? && !strict? && allows_nil?) nil else validate(BigDecimal(new_value.to_s)) new_value.to_s end end # The Frodo type name def type 'Edm.Decimal' end # Value to be used in URLs. # @return [String] def url_value "#{value.to_f}" end private def validate(value) if value > max_value || value < min_value || value.precs.first > 29 validation_error "Value is outside accepted range: #{min_value} to #{max_value}, or has more than 29 significant digits" end end def min_value @min ||= BigDecimal(-7.9 * (10**28), 2) end def max_value @max ||= BigDecimal(7.9 * (10**28), 2) end end end end
Version data entries
18 entries across 18 versions & 1 rubygems