Class: Lutaml::Model::Type::Hash
- Defined in:
- lib/lutaml/model/type/hash.rb
Constant Summary
Constants inherited from Value
Value::EMPTY_OPTIONS, Value::LIST_FACETS, Value::MAX_FACETS, Value::MIN_FACETS, Value::WHITE_SPACE_MODES
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
- .cast(value) ⇒ Object
-
.default_xsd_type ⇒ String
XSD type for Hash.
- .normalize_hash(hash) ⇒ Object
- .normalize_value(value) ⇒ Object
- .serialize(value) ⇒ Object
Methods inherited from Value
enumeration, exclusive, facets, format_type_serializer_for, fraction_digits, from_format, inclusive, inherited, #initialize, #initialized?, length, pattern, register_format_to_from_methods, register_format_type_serializer, tighter_facet, #to_s, total_digits, white_space
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) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lutaml/model/type/hash.rb', line 7 def self.cast(value) return super if Utils.uninitialized?(value) return nil if value.nil? hash = case value when ::Hash then value when ::Array then value.to_h else value.to_h end normalize_hash(hash) end |
.default_xsd_type ⇒ String
XSD type for Hash
53 54 55 |
# File 'lib/lutaml/model/type/hash.rb', line 53 def self.default_xsd_type "xs:anyType" end |
.normalize_hash(hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lutaml/model/type/hash.rb', line 20 def self.normalize_hash(hash) return hash["text"] if hash.keys == ["text"] hash = hash.to_h if hash.is_a?(Lutaml::Model::MappingHash) normalized_hash = hash.transform_values do |value| normalize_value(value) end normalized_hash["elements"] || normalized_hash end |
.normalize_value(value) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/lutaml/model/type/hash.rb', line 32 def self.normalize_value(value) return value unless value.is_a?(::Hash) nested = normalize_hash(value) nested.is_a?(::Hash) ? nested.except("text") : nested end |
.serialize(value) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lutaml/model/type/hash.rb', line 39 def self.serialize(value) return nil if value.nil? return value if value.is_a?(::Hash) case value when ::Hash then value when ::Array then value.to_h else value.to_h end end |