mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Replace ActiveSupport method
This commit is contained in:
@@ -50,7 +50,7 @@ module Paapi
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def actors
|
||||
|
||||
@@ -8,9 +8,6 @@ module Paapi
|
||||
@http_response = response
|
||||
@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('SearchResult', 'Items')
|
||||
@items_data ||= []
|
||||
@@ -23,24 +20,7 @@ module Paapi
|
||||
@json.dig('SearchResult', 'TotalResultCount')
|
||||
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
|
||||
Reference in New Issue
Block a user