Class: Noiseless::Response::Records

Inherits:
Base
  • Object
show all
Defined in:
lib/noiseless/response/records.rb

Instance Method Summary collapse

Methods inherited from Base

#aggregations, #count, #each_with_index, #empty?, #hits, #include_pagination_info, #length, #response, #result, #results, #suggestions, #took, #total, #total_count

Methods included from Pagination::ResponsePagination

#current_page, #first_page?, #last_page?, #limit_value, #next_page, #offset_value, #out_of_range?, #pagination_metadata, #prev_page, #total_pages

Constructor Details

#initialize(raw_response, model_class) ⇒ Records

Returns a new instance of Records.



6
7
8
9
10
# File 'lib/noiseless/response/records.rb', line 6

def initialize(raw_response, model_class)
  super
  @records = nil
  @record_hit_map = nil
end

Instance Method Details

#eachObject



12
13
14
15
16
# File 'lib/noiseless/response/records.rb', line 12

def each(&)
  return enum_for(__method__) unless block_given?

  records.each(&)
end

#each_with_hitObject



18
19
20
21
22
23
24
25
# File 'lib/noiseless/response/records.rb', line 18

def each_with_hit
  return enum_for(__method__) unless block_given?

  records.each_with_index do |record, index|
    hit = hits[record_hit_map[record] || index]
    yield(record, hit)
  end
end

#map_with_hitObject



27
28
29
30
31
# File 'lib/noiseless/response/records.rb', line 27

def map_with_hit(&)
  return enum_for(__method__) unless block_given?

  each_with_hit.map(&)
end

#recordsObject



33
34
35
# File 'lib/noiseless/response/records.rb', line 33

def records
  @records ||= load_records_with_pagination
end

#to_aObject



43
44
45
# File 'lib/noiseless/response/records.rb', line 43

def to_a
  records
end