Sha256: 1f24e77d8fa9e4372772905f3a2a444835986a25b9d919c8a32d258202f4d125

Contents?: true

Size: 1.26 KB

Versions: 21

Compression:

Stored size: 1.26 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 fptr_nodes(type='default')
        structMap_node(type).xpath('//xmlns:fptr')
      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

21 entries across 21 versions & 1 rubygems

Version Path
ddr-models-2.6.2 lib/ddr/models/structure.rb
ddr-models-2.6.1 lib/ddr/models/structure.rb
ddr-models-2.6.0 lib/ddr/models/structure.rb
ddr-models-2.6.0.rc4 lib/ddr/models/structure.rb
ddr-models-2.6.0.rc3 lib/ddr/models/structure.rb
ddr-models-2.6.0.rc2 lib/ddr/models/structure.rb
ddr-models-2.6.0.rc1 lib/ddr/models/structure.rb
ddr-models-2.5.3 lib/ddr/models/structure.rb
ddr-models-2.5.2 lib/ddr/models/structure.rb
ddr-models-2.5.1 lib/ddr/models/structure.rb
ddr-models-2.5.0 lib/ddr/models/structure.rb
ddr-models-2.5.0.rc1 lib/ddr/models/structure.rb
ddr-models-2.4.16 lib/ddr/models/structure.rb
ddr-models-2.4.15 lib/ddr/models/structure.rb
ddr-models-2.4.14 lib/ddr/models/structure.rb
ddr-models-2.4.13 lib/ddr/models/structure.rb
ddr-models-2.4.12 lib/ddr/models/structure.rb
ddr-models-2.4.11 lib/ddr/models/structure.rb
ddr-models-2.4.10 lib/ddr/models/structure.rb
ddr-models-2.4.9 lib/ddr/models/structure.rb