Class: Lutaml::Model::Type::Integer
- Defined in:
- lib/lutaml/model/type/integer.rb
Constant Summary
Constants inherited from Value
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
-
.cast(value, options = {}) ⇒ Object
Performance-optimized cast with short-circuit for already-correct types.
-
.default_xsd_type ⇒ String
Default XSD type for Integer.
-
.serialize(value) ⇒ Object
Override serialize to return Integer instead of String.
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
Performance-optimized cast with short-circuit for already-correct types
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lutaml/model/type/integer.rb', line 8 def self.cast(value, = {}) return nil if value.nil? return value if Utils.uninitialized?(value) # Short-circuit: return immediately if already an Integer # Use identity check for EMPTY_OPTIONS (faster than .empty?) return value if value.is_a?(::Integer) && .equal?(EMPTY_OPTIONS) return 1 if value === true return 0 if value === false value = case value when ::String if value.match?(/^0[0-7]+$/) # Octal value.to_i(8) elsif value.match?(/^-?\d+(\.\d+)?(e-?\d+)?$/i) # Float/exponential Float(value).to_i else begin Integer(value, 10) rescue StandardError nil end end else begin Integer(value) rescue StandardError nil end end unless .equal?(EMPTY_OPTIONS) Model::Services::Type::Validator::Number.validate!(value, ) end value end |
.default_xsd_type ⇒ String
Default XSD type for Integer
56 57 58 |
# File 'lib/lutaml/model/type/integer.rb', line 56 def self.default_xsd_type "xs:integer" end |
.serialize(value) ⇒ Object
Override serialize to return Integer instead of String
47 48 49 50 51 |
# File 'lib/lutaml/model/type/integer.rb', line 47 def self.serialize(value) return nil if value.nil? cast(value) end |