Sha256: 4e7ef0b1f0b53569d26571ba265f69d4e542d899df97de028126d83f4e0c1825

Contents?: true

Size: 884 Bytes

Versions: 20

Compression:

Stored size: 884 Bytes

Contents

module Ddr::Models::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 ark
      href if ark?
    end

    def repo_id
      SolrDocument.find_by_permanent_id(ark).id if ark?
    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

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/models/structures/mptr.rb
ddr-models-2.10.2 lib/ddr/models/structures/mptr.rb
ddr-models-2.10.1 lib/ddr/models/structures/mptr.rb
ddr-models-2.10.0 lib/ddr/models/structures/mptr.rb
ddr-models-2.10.0.rc2 lib/ddr/models/structures/mptr.rb
ddr-models-2.10.0.rc1 lib/ddr/models/structures/mptr.rb
ddr-models-2.9.2 lib/ddr/models/structures/mptr.rb
ddr-models-2.9.1 lib/ddr/models/structures/mptr.rb
ddr-models-2.9.0 lib/ddr/models/structures/mptr.rb
ddr-models-2.9.0.rc1 lib/ddr/models/structures/mptr.rb
ddr-models-2.8.0 lib/ddr/models/structures/mptr.rb
ddr-models-2.8.0.rc1 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.6 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.5 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.4 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.3 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.2 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.1 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.0 lib/ddr/models/structures/mptr.rb
ddr-models-2.7.0.rc1 lib/ddr/models/structures/mptr.rb