Class: Avromatic::Model::Types::DecimalType
- Inherits:
-
AbstractType
- Object
- AbstractType
- Avromatic::Model::Types::DecimalType
- Defined in:
- lib/avromatic/model/types/decimal_type.rb
Constant Summary collapse
- VALUE_CLASSES =
[::BigDecimal].freeze
- INPUT_CLASSES =
[::BigDecimal, ::Float, ::Integer].freeze
Instance Attribute Summary collapse
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Instance Method Summary collapse
- #coerce(input) ⇒ Object
-
#initialize(precision:, scale: 0) ⇒ DecimalType
constructor
A new instance of DecimalType.
- #input_classes ⇒ Object
- #name ⇒ Object
- #referenced_model_classes ⇒ Object
- #serialize(value, _strict) ⇒ Object
- #value_classes ⇒ Object
Methods inherited from AbstractType
Constructor Details
#initialize(precision:, scale: 0) ⇒ DecimalType
Returns a new instance of DecimalType.
16 17 18 19 20 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 16 def initialize(precision:, scale: 0) super() @precision = precision @scale = scale end |
Instance Attribute Details
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
14 15 16 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 14 def precision @precision end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
14 15 16 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 14 def scale @scale end |
Instance Method Details
#coerce(input) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 34 def coerce(input) case input when ::NilClass, ::BigDecimal input when ::Float, ::Integer input.to_d else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end |
#input_classes ⇒ Object
26 27 28 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 26 def input_classes INPUT_CLASSES end |
#name ⇒ Object
30 31 32 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 30 def name "decimal(#{precision}, #{scale})" end |
#referenced_model_classes ⇒ Object
49 50 51 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 49 def referenced_model_classes EMPTY_ARRAY end |
#serialize(value, _strict) ⇒ Object
45 46 47 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 45 def serialize(value, _strict) value end |
#value_classes ⇒ Object
22 23 24 |
# File 'lib/avromatic/model/types/decimal_type.rb', line 22 def value_classes VALUE_CLASSES end |