0
0
Fork 0

Change first_of_value to first_of_hash, and add more test cases (#33647)

This commit is contained in:
Jonathan de Jong 2025-01-22 15:02:05 +01:00 committed by GitHub
parent e155aab39e
commit b18caff5b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 5 deletions

View file

@ -46,7 +46,7 @@ class LinkDetailsExtractor
end
def image
obj = first_of_value(json['image'])
obj = first_of_hash(json['image'])
return obj['url'] if obj.is_a?(Hash)
@ -85,15 +85,15 @@ class LinkDetailsExtractor
private
def author
first_of_value(json['author']) || {}
first_of_hash(json['author']) || {}
end
def publisher
first_of_value(json['publisher']) || {}
first_of_hash(json['publisher']) || {}
end
def first_of_value(arr)
arr.is_a?(Array) ? arr.first : arr
def first_of_hash(arr)
arr.is_a?(Array) ? arr.flatten.find { |item| item.is_a?(Hash) } : arr
end
def root_array(root)