class Alma::LoanSet
Attributes
raw_response[R]
results[R]
Public Class Methods
new(raw_response, search_args = {})
click to toggle source
# File lib/alma/loan_set.rb, line 14 def initialize(raw_response, search_args = {}) @raw_response = raw_response @response = raw_response.parsed_response @search_args = search_args validate(raw_response) @results = @response.fetch(key, []) .map { |item| single_record_class.new(item) } # args passed to the search that returned this set # such as limit, expand, order_by, etc end
Public Instance Methods
all()
click to toggle source
# File lib/alma/loan_set.rb, line 39 def all Enumerator.new do |yielder| offset = 0 loop do extra_args = @search_args.merge({ limit: 100, offset: offset }) r = (offset == 0) ? self : single_record_class.where_user(user_id, extra_args) unless r.empty? r.map { |item| yielder << item } offset += 100 else raise StopIteration end end end end
each(&block)
click to toggle source
# File lib/alma/loan_set.rb, line 55 def each(&block) @results.each(&block) end
key()
click to toggle source
# File lib/alma/loan_set.rb, line 63 def key "item_loan" end
loggable()
click to toggle source
# File lib/alma/loan_set.rb, line 25 def loggable { search_args: @search_args, uri: @raw_response&.request&.uri.to_s }.select { |k, v| !(v.nil? || v.empty?) } end
single_record_class()
click to toggle source
# File lib/alma/loan_set.rb, line 67 def single_record_class Alma::Loan end
success?()
click to toggle source
# File lib/alma/loan_set.rb, line 59 def success? raw_response.response.code.to_s == "200" end
validate(response)
click to toggle source
# File lib/alma/loan_set.rb, line 31 def validate(response) if response.code != 200 error = "Could not find loans info." log = loggable.merge(response.parsed_response) raise ResponseError.new(error, log) end end
Private Instance Methods
user_id()
click to toggle source
# File lib/alma/loan_set.rb, line 72 def user_id @user_id ||= results.first.user_id end