class Alma::BibItemSet
Constants
- ITEMS_PER_PAGE
Attributes
items[RW]
raw_response[R]
total_record_count[R]
Public Class Methods
new(response, options = {})
click to toggle source
# File lib/alma/bib_item_set.rb, line 16 def initialize(response, options = {}) @raw_response = response parsed = response.parsed_response @total_record_count = parsed["total_record_count"] @options = options @mms_id = @options.delete(:mms_id) validate(response) @items = parsed.fetch(key, []).map { |item| single_record_class.new(item) } end
Public Instance Methods
all()
click to toggle source
# File lib/alma/bib_item_set.rb, line 51 def all @last_page_index ||= false Enumerator.new do |yielder| offset = 0 while (!@last_page_index || @last_page_index >= offset / items_per_page) do r = (offset == 0) ? self : single_record_class.find(@mms_id, options = @options.merge({ limit: items_per_page, offset: offset })) unless r.empty? r.map { |item| yielder << item } @last_page_index = (offset / items_per_page) else @last_page_index = @last_page_index ? @last_page_index - 1 : -1 end if r.size == items_per_page @last_page_index += 1 end offset += items_per_page end end end
each(&block)
click to toggle source
# File lib/alma/bib_item_set.rb, line 73 def each(&block) @items.each(&block) end
filter_missing_and_lost()
click to toggle source
# File lib/alma/bib_item_set.rb, line 45 def filter_missing_and_lost clone = dup clone.items = reject(&:missing_or_lost?) clone end
grouped_by_library()
click to toggle source
# File lib/alma/bib_item_set.rb, line 41 def grouped_by_library group_by(&:library) end
items_per_page()
click to toggle source
# File lib/alma/bib_item_set.rb, line 89 def items_per_page ITEMS_PER_PAGE end
key()
click to toggle source
# File lib/alma/bib_item_set.rb, line 81 def key "item" end
loggable()
click to toggle source
# File lib/alma/bib_item_set.rb, line 27 def loggable { total_record_count: @total_record_count.to_s, mms_id: @mms_id, 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/bib_item_set.rb, line 85 def single_record_class Alma::BibItem end
success?()
click to toggle source
# File lib/alma/bib_item_set.rb, line 77 def success? raw_response.response.code.to_s == "200" end
validate(response)
click to toggle source
# File lib/alma/bib_item_set.rb, line 34 def validate(response) if response.code != 200 log = loggable.merge(response.parsed_response) raise ResponseError.new("Could not get bib items.", log) end end