Class: Cocina::Models::Mapping::FromMods::Purl
- Inherits:
-
Object
- Object
- Cocina::Models::Mapping::FromMods::Purl
- Defined in:
- lib/cocina/models/mapping/from_mods/purl.rb
Overview
Support for mapping PURLs.
Class Method Summary collapse
- .primary_purl_node(resource_element, purl) ⇒ Object
- .primary_purl_value(resource_element, purl) ⇒ Object
- .purl_note(purl_node) ⇒ Object
- .purl_value(purl_node) ⇒ Object
Class Method Details
.primary_purl_node(resource_element, purl) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cocina/models/mapping/from_mods/purl.rb', line 9 def self.primary_purl_node(resource_element, purl) purl_nodes = resource_element.xpath('mods:location/mods:url', mods: Description::DESC_METADATA_NS).select do |url_node| Cocina::Models::Mapping::Purl.purl?(url_node.text) end return purl_nodes.find { |purl_node| purl_value(purl_node) == purl } if purl # Prefer a primary PURL node primary_purl_node = purl_nodes.find { |purl_node| purl_node[:usage] == 'primary display' } primary_purl_node || purl_nodes.first end |
.primary_purl_value(resource_element, purl) ⇒ Object
41 42 43 |
# File 'lib/cocina/models/mapping/from_mods/purl.rb', line 41 def self.primary_purl_value(resource_element, purl) purl_value(primary_purl_node(resource_element, purl)) end |
.purl_note(purl_node) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cocina/models/mapping/from_mods/purl.rb', line 23 def self.purl_note(purl_node) notes = [] if purl_node[:note] notes << { value: purl_node['note'], appliesTo: [{ value: 'purl' }] } end if purl_node['displayLabel'] notes << { value: purl_node['displayLabel'], type: 'display label', appliesTo: [{ value: 'purl' }] } end notes end |
.purl_value(purl_node) ⇒ Object
45 46 47 48 |
# File 'lib/cocina/models/mapping/from_mods/purl.rb', line 45 def self.purl_value(purl_node) # Note that normalizing http to https purl_node&.content&.sub(/^https?/, 'https')&.presence end |