Class: Board::CandidateSearch

Inherits:
API::Base show all
Defined in:
lib/board/candidate_search.rb

Constant Summary collapse

DEFAULT_PER_PAGE =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CandidateSearch

Returns a new instance of CandidateSearch.



9
10
11
12
13
# File 'lib/board/candidate_search.rb', line 9

def initialize(*args)
  @params = args.pop
  self.page = params[:page] || 1
  super
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



53
54
55
# File 'lib/board/candidate_search.rb', line 53

def errors
  @errors
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/board/candidate_search.rb', line 7

def params
  @params
end

Instance Method Details

#each_resultObject



15
16
17
18
19
20
21
22
23
# File 'lib/board/candidate_search.rb', line 15

def each_result
  (1..total_pages).each do |page|
    self.page = page
    results.each do |result|
      yield result
    end
    clear
  end
end

#pageObject



41
42
43
# File 'lib/board/candidate_search.rb', line 41

def page
  params[:page]
end

#page=(value) ⇒ Object



45
46
47
# File 'lib/board/candidate_search.rb', line 45

def page=(value)
  params[:page] = value
end

#per_pageObject



37
38
39
# File 'lib/board/candidate_search.rb', line 37

def per_page
  params[:per_page] || DEFAULT_PER_PAGE
end

#resultsObject



29
30
31
# File 'lib/board/candidate_search.rb', line 29

def results
  response['results']
end

#totalObject



33
34
35
# File 'lib/board/candidate_search.rb', line 33

def total
  response['total']
end

#total_pagesObject



25
26
27
# File 'lib/board/candidate_search.rb', line 25

def total_pages
  (total / per_page.to_f).ceil
end

#valid?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/board/candidate_search.rb', line 49

def valid?
  response && (errors.nil? || errors.size == 0)
end