Sha256: 0c51092ada62f594666dfd9077eaac9f7427a63fd6f960b0277ab1376f7ff8f7

Contents?: true

Size: 1.38 KB

Versions: 30

Compression:

Stored size: 1.38 KB

Contents

require "lutaml/lutaml_path/document_wrapper"

module Lutaml
  module Xml
    module LutamlPath
      class DocumentWrapper < ::Lutaml::LutamlPath::DocumentWrapper
        protected

        def serialize_document(document)
          serialize_to_hash(document)
        end

        def serialize_to_hash(object)
          hash = {}
          attribute_name = nil

          object.all_content.each do |mapping, content|
            if mapping == "content"
              attribute_name = object.class.xml_mapping.content.attribute.to_s
              hash[attribute_name] ||= []
              hash[attribute_name] << content.strip unless content.strip&.empty?
            elsif content.is_a?(String)
              if object.class.attributes[mapping.attribute].collection?
                hash[mapping.name] ||= []
                hash[mapping.name] << content.strip
              else
                hash[mapping.name] = content.strip
              end
            else
              if object.class.attributes[mapping.attribute].collection?
                hash[mapping.name] ||= []
                hash[mapping.name] << serialize_to_hash(content)
              else
                hash[mapping.name] = serialize_to_hash(content)
              end
            end
          end

          hash[attribute_name] = hash[attribute_name].compact if attribute_name
          hash
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
lutaml-0.9.27 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.26 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.25 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.24 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.23 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.22 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.21 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.20 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.19 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.18 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.17 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.16 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.15 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.14 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.13 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.12 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.11 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.10 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.9 lib/lutaml/xml/lutaml_path/document_wrapper.rb
lutaml-0.9.8 lib/lutaml/xml/lutaml_path/document_wrapper.rb