Class: CareerBuilder::Resume::LazyCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/career_builder/resume/lazy_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options) ⇒ LazyCollection

Returns a new instance of LazyCollection.



7
8
9
10
# File 'lib/career_builder/resume/lazy_collection.rb', line 7

def initialize(client, options)
  @client = client
  @search_options = options
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/career_builder/resume/lazy_collection.rb', line 5

def client
  @client
end

#search_optionsObject (readonly)

Returns the value of attribute search_options.



5
6
7
# File 'lib/career_builder/resume/lazy_collection.rb', line 5

def search_options
  @search_options
end

Instance Method Details

#eachObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/career_builder/resume/lazy_collection.rb', line 12

def each
  current_page = search_options[:page] || 1

  search = client.advanced_resume_search(search_options.merge(:page_number => current_page))

  results = search.results
  hits = search.hits
  max_page = search.max_page

  loop do

    results.each do |resume|
      yield Resume.new(client, resume)
    end

    current_page += 1

    break if current_page > max_page

    search = client.advanced_resume_search(search_options.merge(:page_number => current_page))
    results = search.results

  end
end