about summary refs log tree commit diff
path: root/app/lib/link_details_extractor.rb
diff options
context:
space:
mode:
authorNick Schonning <nschonni@gmail.com>2023-02-18 17:09:40 -0500
committerGitHub <noreply@github.com>2023-02-19 07:09:40 +0900
commit2177daeae92b77be6797ba8f2ab6ebe1e641e078 (patch)
tree2cf004cd1611bd53f21cdb8021e98aa499448627 /app/lib/link_details_extractor.rb
parent167709f6b0731c163619c58afcb0ca11bb393e54 (diff)
Autofix Rubocop Style/RedundantBegin (#23703)
Diffstat (limited to 'app/lib/link_details_extractor.rb')
-rw-r--r--app/lib/link_details_extractor.rb30
1 files changed, 14 insertions, 16 deletions
diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb
index 2e0672abe..74a7d0f3b 100644
--- a/app/lib/link_details_extractor.rb
+++ b/app/lib/link_details_extractor.rb
@@ -232,26 +232,24 @@ class LinkDetailsExtractor
   end
 
   def structured_data
-    @structured_data ||= begin
-      # Some publications have more than one JSON-LD definition on the page,
-      # and some of those definitions aren't valid JSON either, so we have
-      # to loop through here until we find something that is the right type
-      # and doesn't break
-      document.xpath('//script[@type="application/ld+json"]').filter_map do |element|
-        json_ld = element.content&.gsub(CDATA_JUNK_PATTERN, '')
+    # Some publications have more than one JSON-LD definition on the page,
+    # and some of those definitions aren't valid JSON either, so we have
+    # to loop through here until we find something that is the right type
+    # and doesn't break
+    @structured_data ||= document.xpath('//script[@type="application/ld+json"]').filter_map do |element|
+      json_ld = element.content&.gsub(CDATA_JUNK_PATTERN, '')
 
-        next if json_ld.blank?
+      next if json_ld.blank?
 
-        structured_data = StructuredData.new(html_entities.decode(json_ld))
+      structured_data = StructuredData.new(html_entities.decode(json_ld))
 
-        next unless structured_data.valid?
+      next unless structured_data.valid?
 
-        structured_data
-      rescue Oj::ParseError, EncodingError
-        Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" }
-        next
-      end.first
-    end
+      structured_data
+    rescue Oj::ParseError, EncodingError
+      Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" }
+      next
+    end.first
   end
 
   def document