Class: Lutaml::Model::Type::Decimal
- Defined in:
- lib/lutaml/model/type/decimal.rb
Constant Summary
Constants inherited from Value
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
- .cast(value, options = {}) ⇒ Object
- .check_dependencies!(value) ⇒ Object
-
.default_xsd_type ⇒ String
XSD type for Decimal.
-
.serialize(value) ⇒ Object
# xs:decimal format.
Methods inherited from Value
format_type_serializer_for, from_format, #initialize, #initialized?, register_format_to_from_methods, register_format_type_serializer, #to_s
Methods included from Xml::Type::Configurable
Methods included from UninitializedClassGuard
Constructor Details
This class inherits a constructor from Lutaml::Model::Type::Value
Class Method Details
.cast(value, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lutaml/model/type/decimal.rb', line 7 def self.cast(value, = {}) return nil if value.nil? return value if Utils.uninitialized?(value) 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 # Use identity check for EMPTY_OPTIONS (faster than .empty?) unless .equal?(EMPTY_OPTIONS) Model::Services::Type::Validator::Number.validate!(value, ) end value rescue ArgumentError nil end |
.check_dependencies!(value) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lutaml/model/type/decimal.rb', line 48 def self.check_dependencies!(value) return if defined?(BigDecimal) begin require "bigdecimal" rescue LoadError nil end unless defined?(BigDecimal) raise TypeNotEnabledError.new("Decimal", value) end end |
.default_xsd_type ⇒ String
XSD type for Decimal
44 45 46 |
# File 'lib/lutaml/model/type/decimal.rb', line 44 def self.default_xsd_type "xs:decimal" end |
.serialize(value) ⇒ Object
# xs:decimal format
31 32 33 34 35 36 37 38 39 |
# File 'lib/lutaml/model/type/decimal.rb', line 31 def self.serialize(value) return nil if value.nil? check_dependencies!(value) return value.to_s("F") if value.is_a?(BigDecimal) value&.to_s end |