Class: Ddr::Structures::Mptr

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ddr/structures/mptr.rb

Overview

Wraps a Nokogiri (XML) ‘mptr’ node

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(args) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/ddr/structures/mptr.rb', line 47

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

Instance Method Details

#arkObject



31
32
33
# File 'lib/ddr/structures/mptr.rb', line 31

def ark
  href if ark?
end

#ark?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ddr/structures/mptr.rb', line 23

def ark?
  loctype == 'ARK'
end

#dereferenced_hashObject



43
44
45
# File 'lib/ddr/structures/mptr.rb', line 43

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

#hrefObject



19
20
21
# File 'lib/ddr/structures/mptr.rb', line 19

def href
  self['xlink:href']
end

#idObject



7
8
9
# File 'lib/ddr/structures/mptr.rb', line 7

def id
  self['ID']
end

#loctypeObject



11
12
13
# File 'lib/ddr/structures/mptr.rb', line 11

def loctype
  self['LOCTYPE']
end

#otherloctypeObject



15
16
17
# File 'lib/ddr/structures/mptr.rb', line 15

def otherloctype
  self['OTHERLOCTYPE']
end

#repo_idObject



35
36
37
38
39
40
41
# File 'lib/ddr/structures/mptr.rb', line 35

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

#urn?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ddr/structures/mptr.rb', line 27

def urn?
  loctype == 'URN'
end