Sha256: d1de4f1cf13c90a42e8cd02feb129f35b6e11bcc1a8766a59b1423b8b7dfd6ad

Contents?: true

Size: 991 Bytes

Versions: 10

Compression:

Stored size: 991 Bytes

Contents

module Ddr::Structures
  #
  # Wraps a Nokogiri (XML) 'mptr' node
  #
  class Mptr < SimpleDelegator

    def id
      self['ID']
    end

    def loctype
      self['LOCTYPE']
    end

    def otherloctype
      self['OTHERLOCTYPE']
    end

    def href
      self['xlink:href']
    end

    def ark?
      loctype == 'ARK'
    end

    def urn?
      loctype == 'URN'
    end

    def ark
      href if ark?
    end

    def repo_id
      if ark?
        SolrDocument.find_by_permanent_id(ark).id
      elsif urn?
        href.sub(/^urn:uuid:/, '')
      end
    end

    def dereferenced_hash
      { id: id, repo_id: repo_id }.compact
    end

    def self.build(args)
      node = Nokogiri::XML::Node.new('mptr', args[:document])
      node['ID'] = args[:id] if args[:id]
      node['LOCTYPE'] = args[:loctype] if args[:loctype]
      node['OTHERLOCTYPE'] = args[:otherloctype] if args[:otherloctype]
      node['xlink:href'] = args[:href] if args[:href]
      node
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ddr-core-1.17.0 lib/ddr/structures/mptr.rb
ddr-core-1.16.0 lib/ddr/structures/mptr.rb
ddr-core-1.15.0 lib/ddr/structures/mptr.rb
ddr-core-1.14.0 lib/ddr/structures/mptr.rb
ddr-core-1.13.2 lib/ddr/structures/mptr.rb
ddr-core-1.13.1 lib/ddr/structures/mptr.rb
ddr-core-1.13.0 lib/ddr/structures/mptr.rb
ddr-core-1.12.2 lib/ddr/structures/mptr.rb
ddr-core-1.12.1 lib/ddr/structures/mptr.rb
ddr-core-1.12.0 lib/ddr/structures/mptr.rb