Class: Barker::Round

Inherits:
Object
  • Object
show all
Defined in:
lib/barker/round.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @question = question
  @candidates = candidates
  @started_at = nil
  @finished_at = nil
  @guideline = options[:guideline]
end

Instance Attribute Details

#candidatesObject (readonly)

Returns the value of attribute candidates.



3
4
5
# File 'lib/barker/round.rb', line 3

def candidates
  @candidates
end

#finished_atObject (readonly)

Returns the value of attribute finished_at.



3
4
5
# File 'lib/barker/round.rb', line 3

def finished_at
  @finished_at
end

#guidelineObject (readonly)

Returns the value of attribute guideline.



3
4
5
# File 'lib/barker/round.rb', line 3

def guideline
  @guideline
end

#questionObject (readonly)

Returns the value of attribute question.



3
4
5
# File 'lib/barker/round.rb', line 3

def question
  @question
end

#started_atObject (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, options = {})
  candidate_round(candidate_id).ask(options)
end

#candidate_questionsObject



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_roundsObject



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

#finishObject



25
26
27
# File 'lib/barker/round.rb', line 25

def finish
  @finished_at = Time.now unless finished?
end

#finished?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


33
34
35
# File 'lib/barker/round.rb', line 33

def running?
  started? && !finished?
end

#startObject



17
18
19
# File 'lib/barker/round.rb', line 17

def start
  @started_at = Time.now unless started?
end

#started?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/barker/round.rb', line 21

def started?
  !!started_at
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/barker/round.rb', line 13

def valid?
  question.valid? && candidates.any?
end