Class: Attributor::BigDecimal
- Defined in:
- lib/attributor/types/bigdecimal.rb
Class Method Summary collapse
- .example(context = nil, **options) ⇒ Object
- .load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
- .native_type ⇒ Object
Methods inherited from Numeric
Methods included from Type
Class Method Details
.example(context = nil, **options) ⇒ Object
11 12 13 |
# File 'lib/attributor/types/bigdecimal.rb', line 11 def self.example(context=nil, **) return ::BigDecimal.new("#{/\d{3}/.gen}.#{/\d{3}/.gen}") end |
.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/attributor/types/bigdecimal.rb', line 15 def self.load(value,context=Attributor::DEFAULT_ROOT_CONTEXT, **) return nil if value.nil? return value if value.is_a?(self.native_type) if value.kind_of?(::Float) return BigDecimal(value, 10) end return BigDecimal(value) end |
.native_type ⇒ Object
7 8 9 |
# File 'lib/attributor/types/bigdecimal.rb', line 7 def self.native_type return ::BigDecimal end |