Sha256: b49709d50b94de09d7069cc07fbb98c6aa80e73f124a2bf80fede2bcd23d4d5d

Contents?: true

Size: 1.34 KB

Versions: 14

Compression:

Stored size: 1.34 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 default_struct_map
        struct_maps['default'] || struct_maps[struct_maps.keys.first]
      end

      def default_struct_map_ids
        default_struct_map.pids
      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

14 entries across 14 versions & 1 rubygems

Version Path
ddr-models-3.0.0.beta.16 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.15 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.14 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.13 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.12 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.11 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.10 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.9 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.8 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.7 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.6 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.4 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.3 lib/ddr/models/structure.rb
ddr-models-3.0.0.beta.2 lib/ddr/models/structure.rb