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) ⇒ 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, register_format_to_from_methods, #to_s
Constructor Details
This class inherits a constructor from Lutaml::Model::Type::Value
Class Method Details
.cast(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lutaml/model/type/decimal.rb', line 5 def self.cast(value) return nil if value.nil? check_dependencies!(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 rescue ArgumentError nil end |
.check_dependencies!(value) ⇒ Object
30 31 32 33 34 |
# File 'lib/lutaml/model/type/decimal.rb', line 30 def self.check_dependencies!(value) unless defined?(BigDecimal) raise TypeNotEnabledError.new("Decimal", value) end end |
.serialize(value) ⇒ Object
# xs:decimal format
22 23 24 25 26 27 28 |
# File 'lib/lutaml/model/type/decimal.rb', line 22 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
37 38 39 |
# File 'lib/lutaml/model/type/decimal.rb', line 37 def to_yaml value&.to_s("F") end |