Sha256: b6dde676018fc77a5aa601a1ae377474ab917a7cca7191c98b062ceea1b857b4

Contents?: true

Size: 1.16 KB

Versions: 40

Compression:

Stored size: 1.16 KB

Contents

module Ddr
  module Models
    #
    # Wraps a Nokogiri (XML) Document
    #
    class Structure < SimpleDelegator

      def initialize(xml_doc=nil)
        super
      end

      def struct_maps
        @struct_maps ||= build_struct_maps(structMap_nodes)
      end

      def structMap_node(type='default')
        xpath("//xmlns:structMap[@TYPE='#{type}']").first
      end

      def as_xml_document
        __getobj__
      end

      private

      def structMap_nodes
        xpath("//xmlns:structMap")
      end

      def build_struct_maps(structMap_nodes)
        smaps = {}
        structMap_nodes.each do |structMap_node|
          type = structMap_node['TYPE'] || 'default'
          raise StandardError, "Multiple '#{type}' structMaps" if smaps[type].present?
          smaps[type] = Ddr::Models::StructDiv.new(structMap_node)
        end
        smaps
      end

      def self.template
        Nokogiri::XML(
            '<mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
              <structMap TYPE="default" />
            </mets>'
            ) do |config|
                config.noblanks
              end
      end

    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ddr-models-2.4.7 lib/ddr/models/structure.rb
ddr-models-2.4.6 lib/ddr/models/structure.rb
ddr-models-2.4.5 lib/ddr/models/structure.rb
ddr-models-2.4.4 lib/ddr/models/structure.rb
ddr-models-2.4.3 lib/ddr/models/structure.rb
ddr-models-2.4.2 lib/ddr/models/structure.rb
ddr-models-2.4.1 lib/ddr/models/structure.rb
ddr-models-2.4.0 lib/ddr/models/structure.rb
ddr-models-2.4.0.rc6 lib/ddr/models/structure.rb
ddr-models-2.4.0.rc5 lib/ddr/models/structure.rb
ddr-models-2.4.0.rc4 lib/ddr/models/structure.rb
ddr-models-2.4.0.rc3 lib/ddr/models/structure.rb
ddr-models-2.4.0.rc2 lib/ddr/models/structure.rb
ddr-models-2.4.0.rc1 lib/ddr/models/structure.rb
ddr-models-2.3.2 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.1 lib/ddr/models/structure.rb
ddr-models-2.3.1 lib/ddr/models/structure.rb
ddr-models-3.0.0.alpha.4 lib/ddr/models/structure.rb
ddr-models-3.0.0.alpha.3 lib/ddr/models/structure.rb
ddr-models-2.3.0 lib/ddr/models/structure.rb