Class: Lutaml::Model::Type::Decimal
- Defined in:
- lib/lutaml/model/type/decimal.rb
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
- .cast(value, options = {}) ⇒ Object
- .check_dependencies!(value) ⇒ Object
-
.serialize(value) ⇒ Object
# xs:decimal format.
Instance Method Summary collapse
-
#to_yaml ⇒ Object
Override to avoid serializing ruby object in YAML.
Methods inherited from Value
from_format, #initialize, #initialized?, register_format_to_from_methods, #to_s
Constructor Details
This class inherits a constructor from Lutaml::Model::Type::Value
Class Method Details
.cast(value, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lutaml/model/type/decimal.rb', line 5 def self.cast(value, = {}) return nil if value.nil? check_dependencies!(value) value = case value when BigDecimal # If already a BigDecimal, return as-is value else # Convert to string first to handle various input types BigDecimal(value.to_s) end Model::Services::Type::Validator::Number.validate!(value, ) value rescue ArgumentError nil end |
.check_dependencies!(value) ⇒ Object
32 33 34 35 36 |
# File 'lib/lutaml/model/type/decimal.rb', line 32 def self.check_dependencies!(value) unless defined?(BigDecimal) raise TypeNotEnabledError.new("Decimal", value) end end |
.serialize(value) ⇒ Object
# xs:decimal format
24 25 26 27 28 29 30 |
# File 'lib/lutaml/model/type/decimal.rb', line 24 def self.serialize(value) return nil if value.nil? check_dependencies!(value) value = cast(value) value.to_s("F") # Use fixed-point notation to match test expectations end |
Instance Method Details
#to_yaml ⇒ Object
Override to avoid serializing ruby object in YAML
39 40 41 |
# File 'lib/lutaml/model/type/decimal.rb', line 39 def to_yaml value&.to_s("F") end |