Class: PurlFetcher::Client::PublicXmlRecord
- Inherits:
-
Object
- Object
- PurlFetcher::Client::PublicXmlRecord
- Defined in:
- lib/purl_fetcher/client/public_xml_record.rb
Instance Attribute Summary collapse
-
#druid ⇒ Object
readonly
Returns the value of attribute druid.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#catkey ⇒ Object
Catkey value from the DOR identity_metadata, or nil if there is no catkey.
- #collections ⇒ Object
- #constituents ⇒ Object
-
#dor_content_type ⇒ String
the value of the type attribute for a DOR object’s contentMetadata more info about these values is here: consul.stanford.edu/display/chimera/DOR+content+types%2C+resource+types+and+interpretive+metadata consul.stanford.edu/display/chimera/Summary+of+Content+Types%2C+Resource+Types+and+their+behaviors.
- #druid_tree ⇒ Object
-
#encoded_thumb ⇒ String
the thumbnail in publicXML properly URI encoded, including the slash separator.
- #get_value(node) ⇒ Object
-
#initialize(druid, options = {}) ⇒ PublicXmlRecord
constructor
A new instance of PublicXmlRecord.
-
#is_collection ⇒ Object
True if the identityMetadata has <objectType>collection</objectType>, false otherwise.
- #items(&block) ⇒ Object
-
#label ⇒ Object
ObjectLabel value from the DOR identity_metadata, or nil if there is no barcode.
- #mods ⇒ Object
- #mods_display ⇒ Object
-
#parse_sw_image_ids ⇒ Array<String>
the druid and id attribute of resource/file and objectId and fileId of the resource/externalFile elements that match the image, page, or thumb resource type, including extension Also, prepends the corresponding druid and / specifically for Searchworks use.
-
#parse_thumb ⇒ String
Thumb filename with druid prepended, e.g.
-
#predicate_druids(predicate, predicate_ns = 'info:fedora/fedora-system:def/relations-external#') ⇒ Array<String>?
get the druids from predicate relationships in rels-ext from public_xml.
- #public? ⇒ Boolean
- #public_xml ⇒ Object
- #public_xml? ⇒ Boolean
- #public_xml_doc ⇒ Object
- #purl_base_url ⇒ Object
- #purl_fetcher_api_endpoint ⇒ Object
- #purl_fetcher_client ⇒ Object
- #rights ⇒ Object
- #rights_xml ⇒ Object
- #searchworks_id ⇒ Object
- #stanford_mods ⇒ Object
- #stanford_only? ⇒ Boolean
-
#thumb ⇒ String
value is used to tell SearchWorks UI app of specific display needs for objects this comes from the <thumb> element in publicXML or the first image found (as parsed by discovery-indexer).
Constructor Details
#initialize(druid, options = {}) ⇒ PublicXmlRecord
Returns a new instance of PublicXmlRecord.
20 21 22 23 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 20 def initialize(druid, = {}) @druid = druid @options = end |
Instance Attribute Details
#druid ⇒ Object (readonly)
Returns the value of attribute druid.
8 9 10 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 8 def druid @druid end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 8 def @options end |
Class Method Details
.fetch(url) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 10 def self.fetch(url) if defined?(JRUBY_VERSION) response = Manticore.get(url) response.body if response.code == 200 else response = HTTP.get(url) response.body if response.status.ok? end end |
Instance Method Details
#catkey ⇒ Object
Returns catkey value from the DOR identity_metadata, or nil if there is no catkey.
30 31 32 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 30 def catkey get_value(public_xml_doc.xpath("/publicObject/identityMetadata/otherId[@name='catkey']")) end |
#collections ⇒ Object
131 132 133 134 135 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 131 def collections @collections ||= predicate_druids('isMemberOfCollection').map do |druid| PublicXmlRecord.new(druid, ) end end |
#constituents ⇒ Object
137 138 139 140 141 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 137 def constituents @constituents ||= predicate_druids('isConstituentOf').map do |druid| PublicXmlRecord.new(druid, ) end end |
#dor_content_type ⇒ String
the value of the type attribute for a DOR object’s contentMetadata
more info about these values is here:
https://consul.stanford.edu/display/chimera/DOR+content+types%2C+resource+types+and+interpretive+metadata
https://consul.stanford.edu/display/chimera/Summary+of+Content+Types%2C+Resource+Types+and+their+behaviors
99 100 101 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 99 def dor_content_type public_xml_doc.xpath('//contentMetadata/@type').text end |
#druid_tree ⇒ Object
170 171 172 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 170 def druid_tree druid.match(/(..)(...)(..)(....)/).captures.join('/') end |
#encoded_thumb ⇒ String
the thumbnail in publicXML properly URI encoded, including the slash separator
151 152 153 154 155 156 157 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 151 def encoded_thumb thumb=parse_thumb return unless thumb thumb_druid=thumb.split('/').first # the druid (before the first slash) thumb_filename=thumb.split(/[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}[0-9]{4}[\/]/).last # everything after the druid "#{thumb_druid}%2F#{ERB::Util.url_encode(thumb_filename)}" end |
#get_value(node) ⇒ Object
39 40 41 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 39 def get_value(node) (node && node.first) ? node.first.content : nil end |
#is_collection ⇒ Object
Returns true if the identityMetadata has <objectType>collection</objectType>, false otherwise.
81 82 83 84 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 81 def is_collection object_type_nodes = public_xml_doc.xpath('//objectType') object_type_nodes.find_index { |n| %w(collection set).include? n.text.downcase } end |
#items(&block) ⇒ Object
143 144 145 146 147 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 143 def items(&block) return [] unless is_collection purl_fetcher_client.collection_members(druid, &block) end |
#label ⇒ Object
Returns objectLabel value from the DOR identity_metadata, or nil if there is no barcode.
35 36 37 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 35 def label get_value(public_xml_doc.xpath('/publicObject/identityMetadata/objectLabel')) end |
#mods ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 65 def mods @mods ||= if public_xml_doc.xpath('/publicObject/mods:mods', mods: 'http://www.loc.gov/mods/v3').any? public_xml_doc.xpath('/publicObject/mods:mods', mods: 'http://www.loc.gov/mods/v3').first else if defined?(Honeybadger) Honeybadger.notify( 'Unable to find MODS in the public xml; falling back to stand-along mods document', context: { druid: druid } ) end Nokogiri::XML(self.class.fetch(purl_base_url + "/#{druid}.mods")) end end |
#mods_display ⇒ Object
49 50 51 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 49 def mods_display @mods_display ||= ModsDisplay::HTML.new(stanford_mods) end |
#parse_sw_image_ids ⇒ Array<String>
the druid and id attribute of resource/file and objectId and fileId of the resource/externalFile elements that match the image, page, or thumb resource type, including extension Also, prepends the corresponding druid and / specifically for Searchworks use
123 124 125 126 127 128 129 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 123 def parse_sw_image_ids public_xml_doc.xpath('//resource[@type="page" or @type="image" or @type="thumb"]').map do |node| node.xpath('./file[@mimetype="image/jp2"]/@id').map{ |x| "#{@druid.gsub('druid:','')}/" + x } << node.xpath('./externalFile[@mimetype="image/jp2"]').map do |y| "#{y.attributes['objectId'].text.split(':').last}" + "/" + "#{y.attributes['fileId']}" end end.flatten end |
#parse_thumb ⇒ String
Returns thumb filename with druid prepended, e.g. oo000oo0001/filename withspace.jp2.
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 105 def parse_thumb unless public_xml_doc.nil? thumb = public_xml_doc.xpath('//thumb') # first try and parse what is in the thumb node of publicXML, but fallback to the first image if needed if thumb.size == 1 thumb.first.content elsif thumb.size == 0 && parse_sw_image_ids.size > 0 parse_sw_image_ids.first else nil end end end |
#predicate_druids(predicate, predicate_ns = 'info:fedora/fedora-system:def/relations-external#') ⇒ Array<String>?
get the druids from predicate relationships in rels-ext from public_xml
161 162 163 164 165 166 167 168 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 161 def predicate_druids(predicate, predicate_ns = 'info:fedora/fedora-system:def/relations-external#') ns_hash = { 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'pred_ns' => predicate_ns } xpth = "/publicObject/rdf:RDF/rdf:Description/pred_ns:#{predicate}/@rdf:resource" pred_nodes = public_xml_doc.xpath(xpth, ns_hash) pred_nodes.reject { |n| n.value.empty? }.map do |n| n.value.split('druid:').last end end |
#public? ⇒ Boolean
182 183 184 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 182 def public? rights.world_unrestricted? end |
#public_xml ⇒ Object
53 54 55 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 53 def public_xml @public_xml ||= self.class.fetch(purl_base_url + "/#{druid}.xml") end |
#public_xml? ⇒ Boolean
57 58 59 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 57 def public_xml? !!public_xml end |
#public_xml_doc ⇒ Object
61 62 63 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 61 def public_xml_doc @public_xml_doc ||= Nokogiri::XML(public_xml) end |
#purl_base_url ⇒ Object
190 191 192 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 190 def purl_base_url [:purl_url]&.sub(%r{/$}, '') || 'https://purl.stanford.edu' end |
#purl_fetcher_api_endpoint ⇒ Object
194 195 196 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 194 def purl_fetcher_api_endpoint [:purl_fetcher_url] || 'https://purl-fetcher.stanford.edu' end |
#purl_fetcher_client ⇒ Object
198 199 200 201 202 203 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 198 def purl_fetcher_client @purl_fetcher_client ||= PurlFetcher::Client::Reader.new( nil, 'purl_fetcher.api_endpoint' => purl_fetcher_api_endpoint ) end |
#rights ⇒ Object
178 179 180 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 178 def rights @rights ||= ::Dor::RightsAuth.parse(rights_xml) end |
#rights_xml ⇒ Object
174 175 176 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 174 def rights_xml @rights_xml ||= public_xml_doc.xpath('//rightsMetadata').to_s end |
#searchworks_id ⇒ Object
25 26 27 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 25 def searchworks_id catkey.nil? ? druid : catkey end |
#stanford_mods ⇒ Object
43 44 45 46 47 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 43 def stanford_mods @smods_rec ||= Stanford::Mods::Record.new.tap do |smods_rec| smods_rec.from_str(mods.to_s) end end |
#stanford_only? ⇒ Boolean
186 187 188 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 186 def stanford_only? rights.stanford_only_unrestricted? end |
#thumb ⇒ String
value is used to tell SearchWorks UI app of specific display needs for objects this comes from the <thumb> element in publicXML or the first image found (as parsed by discovery-indexer)
89 90 91 92 |
# File 'lib/purl_fetcher/client/public_xml_record.rb', line 89 def thumb return if is_collection encoded_thumb if %w(book image manuscript map webarchive-seed).include?(dor_content_type) end |