Class: Board::CandidateSearch
- Defined in:
- lib/board/candidate_search.rb
Constant Summary collapse
- DEFAULT_PER_PAGE =
10
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #each_result ⇒ Object
-
#initialize(*args) ⇒ CandidateSearch
constructor
A new instance of CandidateSearch.
- #page ⇒ Object
- #page=(value) ⇒ Object
- #per_page ⇒ Object
- #results ⇒ Object
- #total ⇒ Object
- #total_pages ⇒ Object
- #valid? ⇒ Boolean
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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
53 54 55 |
# File 'lib/board/candidate_search.rb', line 53 def errors @errors end |
#params ⇒ Object (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_result ⇒ Object
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 |
#page ⇒ Object
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_page ⇒ Object
37 38 39 |
# File 'lib/board/candidate_search.rb', line 37 def per_page params[:per_page] || DEFAULT_PER_PAGE end |
#results ⇒ Object
29 30 31 |
# File 'lib/board/candidate_search.rb', line 29 def results response['results'] end |
#total ⇒ Object
33 34 35 |
# File 'lib/board/candidate_search.rb', line 33 def total response['total'] end |
#total_pages ⇒ Object
25 26 27 |
# File 'lib/board/candidate_search.rb', line 25 def total_pages (total / per_page.to_f).ceil end |
#valid? ⇒ Boolean
49 50 51 |
# File 'lib/board/candidate_search.rb', line 49 def valid? response && (errors.nil? || errors.size == 0) end |