Class: Barker::Round
- Inherits:
-
Object
- Object
- Barker::Round
- Defined in:
- lib/barker/round.rb
Instance Attribute Summary collapse
-
#candidates ⇒ Object
readonly
Returns the value of attribute candidates.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#guideline ⇒ Object
readonly
Returns the value of attribute guideline.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
-
#answer(candidate_id, answer_index) ⇒ Object
replace answer_index with answer_uid.
- #ask(candidate_id, options = {}) ⇒ Object
- #candidate_questions ⇒ Object
-
#candidate_round(candidate_id) ⇒ Object
TODO: Refactor below.
- #candidate_rounds ⇒ Object
- #finish ⇒ Object
- #finished? ⇒ Boolean
- #given_answer(candidate_id) ⇒ Object
-
#initialize(question, candidates, options = {}) ⇒ Round
constructor
A new instance of Round.
- #joker(candidate, joker) ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #started? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(question, candidates, options = {}) ⇒ Round
Returns a new instance of Round.
5 6 7 8 9 10 11 |
# File 'lib/barker/round.rb', line 5 def initialize(question, candidates, = {}) @question = question @candidates = candidates @started_at = nil @finished_at = nil @guideline = [:guideline] end |
Instance Attribute Details
#candidates ⇒ Object (readonly)
Returns the value of attribute candidates.
3 4 5 |
# File 'lib/barker/round.rb', line 3 def candidates @candidates end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
3 4 5 |
# File 'lib/barker/round.rb', line 3 def finished_at @finished_at end |
#guideline ⇒ Object (readonly)
Returns the value of attribute guideline.
3 4 5 |
# File 'lib/barker/round.rb', line 3 def guideline @guideline end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
3 4 5 |
# File 'lib/barker/round.rb', line 3 def question @question end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
3 4 5 |
# File 'lib/barker/round.rb', line 3 def started_at @started_at end |
Instance Method Details
#answer(candidate_id, answer_index) ⇒ Object
replace answer_index with answer_uid
42 43 44 |
# File 'lib/barker/round.rb', line 42 def answer(candidate_id, answer_index) candidate_round(candidate_id).answer(answer_index) end |
#ask(candidate_id, options = {}) ⇒ Object
37 38 39 |
# File 'lib/barker/round.rb', line 37 def ask(candidate_id, = {}) candidate_round(candidate_id).ask() end |
#candidate_questions ⇒ Object
63 64 65 |
# File 'lib/barker/round.rb', line 63 def candidate_questions candidates.map { |candidate| candidate_round(candidate.id).question } end |
#candidate_round(candidate_id) ⇒ Object
TODO: Refactor below
55 56 57 |
# File 'lib/barker/round.rb', line 55 def candidate_round(candidate_id) candidate_rounds[candidate_id] end |
#candidate_rounds ⇒ Object
59 60 61 |
# File 'lib/barker/round.rb', line 59 def candidate_rounds @candidate_rounds ||= Hash[candidates.map { |candidate| [candidate.id, CandidateRound.new(candidate, self, :guideline => guideline)] }] end |
#finish ⇒ Object
25 26 27 |
# File 'lib/barker/round.rb', line 25 def finish @finished_at = Time.now unless finished? end |
#finished? ⇒ Boolean
29 30 31 |
# File 'lib/barker/round.rb', line 29 def finished? !!finished_at end |
#given_answer(candidate_id) ⇒ Object
46 47 48 |
# File 'lib/barker/round.rb', line 46 def given_answer(candidate_id) candidate_round(candidate_id).given_answer end |
#joker(candidate, joker) ⇒ Object
50 51 52 |
# File 'lib/barker/round.rb', line 50 def joker(candidate, joker) candidate_round(candidate.id).joker(joker) end |
#running? ⇒ Boolean
33 34 35 |
# File 'lib/barker/round.rb', line 33 def running? started? && !finished? end |
#start ⇒ Object
17 18 19 |
# File 'lib/barker/round.rb', line 17 def start @started_at = Time.now unless started? end |
#started? ⇒ Boolean
21 22 23 |
# File 'lib/barker/round.rb', line 21 def started? !!started_at end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/barker/round.rb', line 13 def valid? question.valid? && candidates.any? end |