Class: Barker::Stage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(quiz, candidates, options = {}) ⇒ Stage

Returns a new instance of Stage.



6
7
8
9
10
11
# File 'lib/barker/stage.rb', line 6

def initialize(quiz, candidates, options = {})
  @quiz = quiz
  @candidates = candidates
  @round_counter = -1
  @guideline = options[:guideline]
end

Instance Attribute Details

#candidatesObject (readonly)

Returns the value of attribute candidates.



4
5
6
# File 'lib/barker/stage.rb', line 4

def candidates
  @candidates
end

#guidelineObject (readonly)

Returns the value of attribute guideline.



4
5
6
# File 'lib/barker/stage.rb', line 4

def guideline
  @guideline
end

#quizObject (readonly)

Returns the value of attribute quiz.



4
5
6
# File 'lib/barker/stage.rb', line 4

def quiz
  @quiz
end

Instance Method Details

#current_roundObject



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

def current_round
  round_counter != -1 && rounds[round_counter]
end

#next_roundObject



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

def next_round
  @round_counter += 1
end

#next_round?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/barker/stage.rb', line 29

def next_round?
  !!rounds[round_counter + 1]
end

#round_counterObject



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

def round_counter
  @round_counter
end

#roundsObject



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

def rounds
  @rounds ||= quiz.questions.map { |question| Barker::Round.new(question, candidates, :guideline => guideline) }
end

#valid?Boolean

Returns:

  • (Boolean)


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

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