Class: Attributor::BigDecimal

Inherits:
Numeric
  • Object
show all
Defined in:
lib/attributor/types/bigdecimal.rb

Class Method Summary collapse

Methods inherited from Numeric

family

Methods included from Type

included

Class Method Details

.example(context = nil, **options) ⇒ Object


11
12
13
# File 'lib/attributor/types/bigdecimal.rb', line 11

def self.example(context=nil, **options)
  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, **options)
  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_typeObject


7
8
9
# File 'lib/attributor/types/bigdecimal.rb', line 7

def self.native_type
  return ::BigDecimal
end