From 1ad818b4d7489582b276a916bf17e9483cb9a461 Mon Sep 17 00:00:00 2001 From: Dan Milne Date: Thu, 24 Oct 2019 14:27:08 +1100 Subject: [PATCH] Ensure Item#contributors always returns an Array. Safe navigator for Item#contributors_of compact - although not really neccessary now. --- lib/paapi/item.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/paapi/item.rb b/lib/paapi/item.rb index 8a4ceb4..b60077f 100644 --- a/lib/paapi/item.rb +++ b/lib/paapi/item.rb @@ -51,18 +51,14 @@ module Paapi end def contributors - get(%w{ItemInfo ByLineInfo Contributors}) + Array(get(%w{ItemInfo ByLineInfo Contributors})) end def contributors_of(kind) - contributors&.select { |e| e['Role'] == kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.capitalize } }&.map do |e| + contributors&.select { |e| e['Role'] == kind.to_s.gsub(/([[:alpha:]]+)/).each { |w| w.capitalize } }&.map do |e| r = e['Name'] Nameable(r) unless r.to_s.empty? - end.compact - end - - def contributors_of1(kind) - contributors&.select { |e| e['Role'] == kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.capitalize } }&.map { |e| Nameable(e['Name'])} + end&.compact end def actors