Replace ActiveSupport method

This commit is contained in:
Dan Milne
2019-10-05 23:19:48 +10:00
parent 8df2dee3b8
commit ac07f65440
2 changed files with 1 additions and 21 deletions

View File

@@ -50,7 +50,7 @@ module Paapi
end end
def contributors_of(kind) def contributors_of(kind)
contributors&.select { |e| e['Role'] == kind.to_s.titlecase }&.map { |e| Nameable(e['Name'])} contributors&.select { |e| e['Role'] == kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.capitalize } }&.map { |e| Nameable(e['Name'])}
end end
def actors def actors

View File

@@ -8,9 +8,6 @@ module Paapi
@http_response = response @http_response = response
@json = JSON.parse(response.body.to_s) @json = JSON.parse(response.body.to_s)
@datas = symbolise(JSON.parse(response.body.to_s))
@doc = JSON.parse(@datas.to_json, object_class: OpenStruct)
@items_data = @json.dig('ItemsResult', 'Items') @items_data = @json.dig('ItemsResult', 'Items')
@items_data ||= @json.dig('SearchResult', 'Items') @items_data ||= @json.dig('SearchResult', 'Items')
@items_data ||= [] @items_data ||= []
@@ -23,24 +20,7 @@ module Paapi
@json.dig('SearchResult', 'TotalResultCount') @json.dig('SearchResult', 'TotalResultCount')
end end
def snake_case(s)
return s.downcase if s.match(/\A[A-Z]+\z/)
s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z])([A-Z])/, '\1_\2').
downcase
end
def symbolise(obj)
if obj.is_a? Hash
return obj.inject({}) do |memo, (k, v)|
memo.tap { |m| m[snake_case(k)] = symbolise(v) }
end
elsif obj.is_a? Array
return obj.map { |memo| symbolise(memo) }
end
obj
end
end end
end end