Sha256: 536315f09fed471c5d02cb0c388328a06c9b397aa147600c300945c4381fe756

Contents?: true

Size: 876 Bytes

Versions: 33

Compression:

Stored size: 876 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 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

33 entries across 33 versions & 1 rubygems

Version Path
ddr-core-1.11.0 lib/ddr/structures/mptr.rb
ddr-core-1.10.0 lib/ddr/structures/mptr.rb
ddr-core-1.9.0 lib/ddr/structures/mptr.rb
ddr-core-1.8.0 lib/ddr/structures/mptr.rb
ddr-core-1.7.0 lib/ddr/structures/mptr.rb
ddr-core-1.6.6 lib/ddr/structures/mptr.rb
ddr-core-1.6.5 lib/ddr/structures/mptr.rb
ddr-core-1.6.4 lib/ddr/structures/mptr.rb
ddr-core-1.6.3 lib/ddr/structures/mptr.rb
ddr-core-1.6.2 lib/ddr/structures/mptr.rb
ddr-core-1.6.1 lib/ddr/structures/mptr.rb
ddr-core-1.6.0 lib/ddr/structures/mptr.rb
ddr-core-1.5.5 lib/ddr/structures/mptr.rb
ddr-core-1.5.4 lib/ddr/structures/mptr.rb
ddr-core-1.5.2 lib/ddr/structures/mptr.rb
ddr-core-1.5.3 lib/ddr/structures/mptr.rb
ddr-core-1.5.1 lib/ddr/structures/mptr.rb
ddr-core-1.4.4 lib/ddr/structures/mptr.rb
ddr-core-1.4.3 lib/ddr/structures/mptr.rb
ddr-core-1.4.2 lib/ddr/structures/mptr.rb