Class: Alma::ResultSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Error, Enumerable
Defined in:
lib/alma/result_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Error

#error, #error_message, #has_error?

Constructor Details

#initialize(response_body_hash) ⇒ ResultSet

Returns a new instance of ResultSet.



15
16
17
# File 'lib/alma/result_set.rb', line 15

def initialize(response_body_hash)
  @response = response_body_hash
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/alma/result_set.rb', line 10

def response
  @response
end

Instance Method Details

#eachObject



24
25
26
27
# File 'lib/alma/result_set.rb', line 24

def each
  @results ||= (@response.fetch(key, []) || [])
    .map { |item| single_record_class.new(item) }
end

#loggableObject



19
20
21
22
# File 'lib/alma/result_set.rb', line 19

def loggable
  { uri: @response&.request&.uri&.to_s }
    .select { |k, v| !(v.nil? || v.empty?) }
end

#total_record_countObject Also known as: total_records



29
30
31
# File 'lib/alma/result_set.rb', line 29

def total_record_count
  fetch("total_record_count", 0).to_i
end