Skip to content

Commit

Permalink
Merge pull request #726 from sul-dlss/avoid-try
Browse files Browse the repository at this point in the history
Use safe navigation rather than try
  • Loading branch information
thatbudakguy authored Oct 24, 2023
2 parents 61ff37b + 7a364d3 commit cd50a29
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/public_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(document)
end

def title
@title ||= document.root.at_xpath('oai_dc:dc/dc:title', oai_dc: 'http://www.openarchives.org/OAI/2.0/oai_dc/', dc: 'http://purl.org/dc/elements/1.1/').try(:text)
@title ||= document.root.at_xpath('oai_dc:dc/dc:title', oai_dc: 'http://www.openarchives.org/OAI/2.0/oai_dc/', dc: 'http://purl.org/dc/elements/1.1/')&.text
end

def rights_metadata
Expand All @@ -18,22 +18,22 @@ def content_metadata
end

def catalog_key
@catalog_key ||= document.root.at_xpath('identityMetadata/otherId[@name="catkey"]').try(:text).presence
@catalog_key ||= document.root.at_xpath('identityMetadata/otherId[@name="catkey"]')&.text.presence
@catalog_key ||= begin
key = document.root.at_xpath('identityMetadata/otherId[@name="folio_instance_hrid"]').try(:text).presence
key = document.root.at_xpath('identityMetadata/otherId[@name="folio_instance_hrid"]')&.text.presence
key = key.delete_prefix('a') if key&.match?(/^a\d+$/)
key
end
end

def released_to?(key)
release = document.root.at_xpath("releaseData/release[@to='#{key}']").try(:text)
release = document.root.at_xpath("releaseData/release[@to='#{key}']")&.text

release == 'true'
end

def thumb
document.root.at_xpath('thumb').try(:text)
document.root.at_xpath('thumb')&.text
end

def relations(predicate)
Expand Down

0 comments on commit cd50a29

Please sign in to comment.