Class: DataComApi::Responses::SearchBase
- Inherits:
-
Base
- Object
- Base
- DataComApi::Responses::SearchBase
show all
- Defined in:
- lib/data-com-api/responses/search_base.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(api_client, received_options) ⇒ SearchBase
Returns a new instance of SearchBase.
9
10
11
12
13
14
15
|
# File 'lib/data-com-api/responses/search_base.rb', line 9
def initialize(api_client, received_options)
@options = received_options
super(api_client)
@page_size = client.page_size
end
|
Instance Method Details
#all ⇒ Object
Also known as:
to_a
Be careful, this will load all records in memory, check total_records before doing such a thing
50
51
52
53
54
55
56
|
# File 'lib/data-com-api/responses/search_base.rb', line 50
def all
all_records = Array.new(self.real_size)
self.each_with_index { |record, index| all_records[index] = record }
all_records
end
|
#at_offset(offset) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/data-com-api/responses/search_base.rb', line 36
def at_offset(offset)
page_options = options.merge(
offset: offset,
page_size: page_size
)
request = self.perform_request(page_options)
calculate_size_from_request! request
self.transform_request request
end
|
#each_with_index ⇒ Object
Also known as:
each
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/data-com-api/responses/search_base.rb', line 58
def each_with_index
total_records = 0
records_per_previous_page = page_size
current_offset = 0
loop do
break if current_offset > self.real_max_offset
records = at_offset(current_offset)
records.each_with_index do |record, index|
yield(record, index + current_offset)
end
records_per_previous_page = records.size
current_offset += page_size
total_records += records_per_previous_page
if records_per_previous_page != page_size || total_records == self.size
break
end
end
end
|
#max_size ⇒ Object
28
29
30
|
# File 'lib/data-com-api/responses/search_base.rb', line 28
def max_size
self.real_max_offset + page_size
end
|
#real_max_offset ⇒ Object
82
83
84
85
86
87
|
# File 'lib/data-com-api/responses/search_base.rb', line 82
def real_max_offset
return @real_max_offset if @real_max_offset
@real_max_offset = client.max_offset
@real_max_offset = @real_max_offset - (@real_max_offset % page_size)
end
|
#real_size ⇒ Object
32
33
34
|
# File 'lib/data-com-api/responses/search_base.rb', line 32
def real_size
self.size > self.real_max_offset ? self.max_size : self.size
end
|
#size ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/data-com-api/responses/search_base.rb', line 17
def size
return @size if @size
size_options = options.merge(
offset: 0,
page_size: client.size_only_page_size
)
calculate_size_from_request! self.perform_request(size_options)
end
|