Class: Alma::BibItemSet
Defined Under Namespace
Classes: ResponseError
Instance Attribute Summary collapse
Attributes inherited from ResultSet
#response
Instance Method Summary
collapse
Methods included from Error
#error, #error_message, #has_error?
Constructor Details
#initialize(response, options = {}) ⇒ BibItemSet
Returns a new instance of BibItemSet.
16
17
18
19
20
21
22
23
24
25
|
# 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
|
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
10
11
12
|
# File 'lib/alma/bib_item_set.rb', line 10
def items
@items
end
|
#raw_response ⇒ Object
Returns the value of attribute raw_response.
11
12
13
|
# File 'lib/alma/bib_item_set.rb', line 11
def raw_response
@raw_response
end
|
#total_record_count ⇒ Object
Returns the value of attribute total_record_count.
11
12
13
|
# File 'lib/alma/bib_item_set.rb', line 11
def total_record_count
@total_record_count
end
|
Instance Method Details
#all ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/alma/bib_item_set.rb', line 51
def all
Enumerator.new do |yielder|
offset = 0
loop do
r = (offset == 0) ? self : single_record_class.find(@mms_id, options=@options.merge({limit: 100, offset: offset}))
unless r.empty?
r.map { |item| yielder << item }
offset += 100
else
raise StopIteration
end
end
end
end
|
#each(&block) ⇒ Object
66
67
68
|
# File 'lib/alma/bib_item_set.rb', line 66
def each(&block)
@items.each(&block)
end
|
#filter_missing_and_lost ⇒ Object
45
46
47
48
49
|
# 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 ⇒ Object
41
42
43
|
# File 'lib/alma/bib_item_set.rb', line 41
def grouped_by_library
group_by(&:library)
end
|
#key ⇒ Object
74
75
76
|
# File 'lib/alma/bib_item_set.rb', line 74
def key
"item"
end
|
#loggable ⇒ Object
27
28
29
30
31
32
|
# File 'lib/alma/bib_item_set.rb', line 27
def loggable
{ total_record_count: @total_record_count,
mms_id: @mms_id,
uri: @raw_response&.request&.uri.to_s
}.select { |k, v| !(v.nil? || v.empty?) }
end
|
#single_record_class ⇒ Object
78
79
80
|
# File 'lib/alma/bib_item_set.rb', line 78
def single_record_class
Alma::BibItem
end
|
#success? ⇒ Boolean
70
71
72
|
# File 'lib/alma/bib_item_set.rb', line 70
def success?
raw_response.response.code.to_s == "200"
end
|
#validate(response) ⇒ Object
34
35
36
37
38
39
|
# 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
|