Class: Harvestdor::Indexer::Resource
- Inherits:
-
Object
- Object
- Harvestdor::Indexer::Resource
- Includes:
- ActiveSupport::Benchmarkable
- Defined in:
- lib/harvestdor/indexer/resource.rb
Instance Attribute Summary collapse
-
#druid ⇒ Object
readonly
Returns the value of attribute druid.
-
#indexer ⇒ Object
readonly
Returns the value of attribute indexer.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#bare_druid ⇒ String
String of form oo123oo1234.
-
#collection? ⇒ Boolean
Is this resource a collection?.
-
#collections ⇒ Array<String>
get the druids from isMemberOfCollection relationships in rels-ext from public_xml.
-
#content_metadata ⇒ Nokogiri::XML::Document
the contentMetadata for this DOR object, ultimately from the purl public xml.
- #dor_fetcher_client ⇒ Object
- #eql?(other) ⇒ Boolean
- #exists? ⇒ Boolean
-
#harvestdor_client ⇒ Object
The harvestdor client used for retrieving resources.
- #hash ⇒ Object
-
#identity_md_obj_label ⇒ String
given a druid, get its objectLabel from its purl page identityMetadata.
-
#identity_metadata ⇒ Nokogiri::XML::Document
the identityMetadata for this DOR object, ultimately from the purl public xml.
-
#initialize(indexer, druid, options = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#items ⇒ Object
Return the items in this collection.
- #items_druids ⇒ Object
-
#logger ⇒ Object
Get the logger.
- #mods ⇒ Object
- #namespaced_druid ⇒ Object
-
#public_xml ⇒ Nokogiri::XML::Document
the public xml for this DOR object, from the purl page.
- #public_xml? ⇒ Boolean deprecated Deprecated.
- #public_xml_or_druid ⇒ Object deprecated Deprecated.
- #purl_fetcher_client ⇒ Object
-
#rdf ⇒ Nokogiri::XML::Document
the RDF for this DOR object, ultimately from the purl public xml.
-
#rights_metadata ⇒ Nokogiri::XML::Document
the rightsMetadata for this DOR object, ultimately from the purl public xml.
-
#smods_rec ⇒ Stanford::Mods::Record
return the MODS for the druid as a Stanford::Mods::Record object.
Constructor Details
#initialize(indexer, druid, options = {}) ⇒ Resource
Returns a new instance of Resource.
11 12 13 14 15 |
# File 'lib/harvestdor/indexer/resource.rb', line 11 def initialize(indexer, druid, = {}) @indexer = indexer @druid = druid @options = end |
Instance Attribute Details
#druid ⇒ Object (readonly)
Returns the value of attribute druid.
7 8 9 |
# File 'lib/harvestdor/indexer/resource.rb', line 7 def druid @druid end |
#indexer ⇒ Object (readonly)
Returns the value of attribute indexer.
7 8 9 |
# File 'lib/harvestdor/indexer/resource.rb', line 7 def indexer @indexer end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/harvestdor/indexer/resource.rb', line 7 def @options end |
Instance Method Details
#bare_druid ⇒ String
Returns string of form oo123oo1234.
26 27 28 |
# File 'lib/harvestdor/indexer/resource.rb', line 26 def @bare_druid ||= druid.gsub('druid:', '') end |
#collection? ⇒ Boolean
Is this resource a collection?
58 59 60 |
# File 'lib/harvestdor/indexer/resource.rb', line 58 def collection? .xpath('/identityMetadata/objectType').any? { |x| x.text == 'collection' } end |
#collections ⇒ Array<String>
get the druids from isMemberOfCollection relationships in rels-ext from public_xml
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/harvestdor/indexer/resource.rb', line 64 def collections @collections ||= begin ns_hash = { 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'fedora' => 'info:fedora/fedora-system:def/relations-external#', '' => '' } is_member_of_nodes ||= public_xml.xpath('/publicObject/rdf:RDF/rdf:Description/fedora:isMemberOfCollection/@rdf:resource', ns_hash) is_member_of_nodes.reject { |n| n.value.empty? }.map do |n| Harvestdor::Indexer::Resource.new(indexer, n.value.gsub('info:fedora/', '')) end end end |
#content_metadata ⇒ Nokogiri::XML::Document
the contentMetadata for this DOR object, ultimately from the purl public xml
149 150 151 152 153 |
# File 'lib/harvestdor/indexer/resource.rb', line 149 def @content_metadata ||= benchmark "content_metadata (#{druid})", level: :debug do harvestdor_client. public_xml end end |
#dor_fetcher_client ⇒ Object
36 37 38 |
# File 'lib/harvestdor/indexer/resource.rb', line 36 def dor_fetcher_client indexer.dor_fetcher_client end |
#eql?(other) ⇒ Boolean
179 180 181 |
# File 'lib/harvestdor/indexer/resource.rb', line 179 def eql?(other) other.is_a?(Harvestdor::Indexer::Resource) && other.indexer == indexer && other.druid == druid end |
#exists? ⇒ Boolean
50 51 52 53 54 |
# File 'lib/harvestdor/indexer/resource.rb', line 50 def exists? public_xml rescue Harvestdor::Errors::MissingPublicXml, Harvestdor::Errors::MissingPurlPage false end |
#harvestdor_client ⇒ Object
The harvestdor client used for retrieving resources
32 33 34 |
# File 'lib/harvestdor/indexer/resource.rb', line 32 def harvestdor_client indexer.harvestdor_client end |
#hash ⇒ Object
183 184 185 |
# File 'lib/harvestdor/indexer/resource.rb', line 183 def hash druid.hash ^ indexer.hash end |
#identity_md_obj_label ⇒ String
given a druid, get its objectLabel from its purl page identityMetadata
99 100 101 102 |
# File 'lib/harvestdor/indexer/resource.rb', line 99 def identity_md_obj_label logger.error("#{druid} missing identityMetadata") unless .xpath('identityMetadata/objectLabel').text end |
#identity_metadata ⇒ Nokogiri::XML::Document
the identityMetadata for this DOR object, ultimately from the purl public xml
157 158 159 160 161 |
# File 'lib/harvestdor/indexer/resource.rb', line 157 def @identity_metadata ||= benchmark "identity_metadata (#{druid})", level: :debug do harvestdor_client. public_xml end end |
#items ⇒ Object
Return the items in this collection
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/harvestdor/indexer/resource.rb', line 77 def items return [] unless collection? # return an enumerator, with an estimated size of the collection return to_enum(:items) { items_druids.count } unless block_given? items_druids.each do |x| yield Harvestdor::Indexer::Resource.new(indexer, x) end end |
#items_druids ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/harvestdor/indexer/resource.rb', line 88 def items_druids if purl_fetcher_client # we don't need to memoize purl_fetcher_client, since it natively uses enumerables purl_fetcher_client.druids_from_collection(namespaced_druid) else @items_druids ||= dor_fetcher_client.druid_array(dor_fetcher_client.get_collection(, {})) end end |
#logger ⇒ Object
Get the logger
46 47 48 |
# File 'lib/harvestdor/indexer/resource.rb', line 46 def logger [:logger] || (indexer.logger if indexer.respond_to? :logger) || Logger.new(STDERR) end |
#mods ⇒ Object
116 117 118 |
# File 'lib/harvestdor/indexer/resource.rb', line 116 def mods @mods ||= harvestdor_client.mods end |
#namespaced_druid ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/harvestdor/indexer/resource.rb', line 17 def namespaced_druid if druid =~ /^druid:/ druid else "druid:#{druid}" end end |
#public_xml ⇒ Nokogiri::XML::Document
the public xml for this DOR object, from the purl page
122 123 124 125 126 |
# File 'lib/harvestdor/indexer/resource.rb', line 122 def public_xml @public_xml ||= benchmark "public_xml(#{druid})", level: :debug do harvestdor_client.public_xml end end |
#public_xml? ⇒ Boolean
Has the public_xml been previously retrieved?
131 132 133 |
# File 'lib/harvestdor/indexer/resource.rb', line 131 def public_xml? !!@public_xml end |
#public_xml_or_druid ⇒ Object
Get the public_xml, if retrieved, or the druid. This is used to short-circuit retrieving metadata out of the public xml.
139 140 141 142 143 144 145 |
# File 'lib/harvestdor/indexer/resource.rb', line 139 def public_xml_or_druid if public_xml? public_xml else end end |
#purl_fetcher_client ⇒ Object
40 41 42 |
# File 'lib/harvestdor/indexer/resource.rb', line 40 def purl_fetcher_client indexer.purl_fetcher_client end |
#rdf ⇒ Nokogiri::XML::Document
the RDF for this DOR object, ultimately from the purl public xml
173 174 175 176 177 |
# File 'lib/harvestdor/indexer/resource.rb', line 173 def rdf @rdf ||= benchmark "rdf (#{druid})", level: :debug do harvestdor_client.rdf public_xml end end |
#rights_metadata ⇒ Nokogiri::XML::Document
the rightsMetadata for this DOR object, ultimately from the purl public xml
165 166 167 168 169 |
# File 'lib/harvestdor/indexer/resource.rb', line 165 def @rights_metadata ||= benchmark "rights_metadata (#{druid})", level: :debug do harvestdor_client. public_xml end end |
#smods_rec ⇒ Stanford::Mods::Record
return the MODS for the druid as a Stanford::Mods::Record object
106 107 108 109 110 111 112 113 114 |
# File 'lib/harvestdor/indexer/resource.rb', line 106 def smods_rec @smods_rec ||= benchmark "smods_rec(#{druid})", level: :debug do ng_doc = mods raise "Empty MODS metadata for #{druid}: #{ng_doc.to_xml}" if ng_doc.root.xpath('//text()').empty? mods_rec = Stanford::Mods::Record.new mods_rec.from_nk_node(ng_doc.root) mods_rec end end |