Class: Attributor::BigDecimal
- Inherits:
-
Object
- Object
- Attributor::BigDecimal
- Includes:
- Numeric
- Defined in:
- lib/attributor/types/bigdecimal.rb
Class Method Summary collapse
- .example(_context = nil, options: {}) ⇒ Object
- .json_schema_type ⇒ Object
- .load(value, _context = Attributor::DEFAULT_ROOT_CONTEXT, **_options) ⇒ Object
- .native_type ⇒ Object
Class Method Details
.example(_context = nil, options: {}) ⇒ Object
10 11 12 |
# File 'lib/attributor/types/bigdecimal.rb', line 10 def self.example(_context = nil, options: {}) BigDecimal("#{/\d{3}/.gen}.#{/\d{3}/.gen}") end |
.json_schema_type ⇒ Object
21 22 23 |
# File 'lib/attributor/types/bigdecimal.rb', line 21 def self.json_schema_type :number end |
.load(value, _context = Attributor::DEFAULT_ROOT_CONTEXT, **_options) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/attributor/types/bigdecimal.rb', line 14 def self.load(value, _context = Attributor::DEFAULT_ROOT_CONTEXT, **) return nil if value.nil? return value if value.is_a?(native_type) return BigDecimal(value, 10) if value.is_a?(::Float) BigDecimal(value) end |
.native_type ⇒ Object
6 7 8 |
# File 'lib/attributor/types/bigdecimal.rb', line 6 def self.native_type ::BigDecimal end |