Module: Lutaml::Model::Serialize

Included in:
Serializable
Defined in:
lib/lutaml/model/serialize.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

FORMATS =
i[xml json yaml toml].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#element_orderObject (readonly)

Returns the value of attribute element_order.



391
392
393
# File 'lib/lutaml/model/serialize.rb', line 391

def element_order
  @element_order
end

Class Method Details

.included(base) ⇒ Object



17
18
19
# File 'lib/lutaml/model/serialize.rb', line 17

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize(attrs = {}) ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/lutaml/model/serialize.rb', line 393

def initialize(attrs = {})
  return unless self.class.attributes

  if attrs.is_a?(Lutaml::Model::MappingHash)
    @ordered = attrs.ordered?
    @element_order = attrs.item_order
  end

  self.class.attributes.each do |name, attr|
    value = self.class.attr_value(attrs, name, attr)

    send(:"#{name}=", self.class.ensure_utf8(value))
  end
end

#key_exist?(hash, key) ⇒ Boolean

Returns:

  • (Boolean)


412
413
414
# File 'lib/lutaml/model/serialize.rb', line 412

def key_exist?(hash, key)
  hash.key?(key) || hash.key?(key.to_sym) || hash.key?(key.to_s)
end

#key_value(hash, key) ⇒ Object



416
417
418
# File 'lib/lutaml/model/serialize.rb', line 416

def key_value(hash, key)
  hash[key] || hash[key.to_sym] || hash[key.to_s]
end

#ordered?Boolean

Returns:

  • (Boolean)


408
409
410
# File 'lib/lutaml/model/serialize.rb', line 408

def ordered?
  @ordered
end