Class: Clearbit::Discovery::PagedResult

Inherits:
Delegator
  • Object
show all
Defined in:
lib/clearbit/discovery.rb

Instance Method Summary collapse

Constructor Details

#initialize(params, response) ⇒ PagedResult

Returns a new instance of PagedResult.



9
10
11
12
# File 'lib/clearbit/discovery.rb', line 9

def initialize(params, response)
  @params = params
  super Mash.new(response)
end

Instance Method Details

#__getobj__Object



14
15
16
# File 'lib/clearbit/discovery.rb', line 14

def __getobj__
  @response
end

#__setobj__(obj) ⇒ Object



18
19
20
# File 'lib/clearbit/discovery.rb', line 18

def __setobj__(obj)
  @response = obj
end

#each(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/clearbit/discovery.rb', line 22

def each(&block)
  return enum_for(:each) unless block_given?

  results.each do |result|
    yield result
  end

  if results.any?
    search = Discovery.search(
      @params.merge(page: page + 1)
    )
    search.each(&block)
  end
end

#map(&block) ⇒ Object



37
38
39
# File 'lib/clearbit/discovery.rb', line 37

def map(&block)
  each.map(&block)
end