module Lutaml::Model::Serialize
def self.included(base)
def self.included(base) base.extend(ClassMethods) end
def initialize(attrs = {})
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 validate end
def key_exist?(hash, key)
def key_exist?(hash, key) hash.key?(key) || hash.key?(key.to_sym) || hash.key?(key.to_s) end
def key_value(hash, key)
def key_value(hash, key) hash[key] || hash[key.to_sym] || hash[key.to_s] end
def ordered?
def ordered? @ordered end
def validate
def validate self.class.attributes.each do |name, attr| value = send(name) unless self.class.attr_value_valid?(name, value) raise Lutaml::Model::InvalidValueError.new(name, value, attr.options[:values]) end end end