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.4.0 lib/ddr/structures/mptr.rb
ddr-core-1.3.0 lib/ddr/structures/mptr.rb
ddr-core-1.2.0 lib/ddr/structures/mptr.rb
ddr-core-1.2.0.rc3 lib/ddr/structures/mptr.rb
ddr-core-1.2.0.rc2 lib/ddr/structures/mptr.rb
ddr-core-1.2.0.rc1 lib/ddr/structures/mptr.rb
ddr-core-1.1.2 lib/ddr/structures/mptr.rb
ddr-core-1.1.1 lib/ddr/structures/mptr.rb
ddr-core-1.1.0 lib/ddr/structures/mptr.rb
ddr-core-1.0.0 lib/ddr/structures/mptr.rb
ddr-core-0.3.0 lib/ddr/structures/mptr.rb
ddr-core-0.2.2 lib/ddr/structures/mptr.rb
ddr-core-0.2.1 lib/ddr/structures/mptr.rb