lib/harvestdor/indexer/resource.rb in harvestdor-indexer-2.4.0 vs lib/harvestdor/indexer/resource.rb in harvestdor-indexer-2.5.0
- old
+ new
@@ -12,10 +12,18 @@
@indexer = indexer
@druid = druid
@options = options
end
+ def namespaced_druid
+ if druid =~ /^druid:/
+ druid
+ else
+ "druid:#{druid}"
+ end
+ end
+
# @return [String] string of form oo123oo1234
def bare_druid
@bare_druid ||= druid.gsub('druid:', '')
end
@@ -27,10 +35,14 @@
def dor_fetcher_client
indexer.dor_fetcher_client
end
+ def purl_fetcher_client
+ indexer.purl_fetcher_client
+ end
+
##
# Get the logger
def logger
options[:logger] || (indexer.logger if indexer.respond_to? :logger) || Logger.new(STDERR)
end
@@ -64,19 +76,24 @@
# Return the items in this collection
def items
return [] unless collection?
# return an enumerator, with an estimated size of the collection
- return to_enum(:items) { items_druids.length } unless block_given?
+ return to_enum(:items) { items_druids.count } unless block_given?
items_druids.each do |x|
yield Harvestdor::Indexer::Resource.new(indexer, x)
end
end
def items_druids
- @items_druids ||= dor_fetcher_client.druid_array(dor_fetcher_client.get_collection(bare_druid, {}))
+ 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(bare_druid, {}))
+ end
end
# given a druid, get its objectLabel from its purl page identityMetadata
# @return [String] the value of the <objectLabel> element in the identityMetadata for the object
def identity_md_obj_label
@@ -165,6 +182,6 @@
def hash
druid.hash ^ indexer.hash
end
end
-end
\ No newline at end of file
+end