Class: Irv::Round
- Inherits:
-
Object
- Object
- Irv::Round
- Defined in:
- lib/irv/round.rb
Instance Attribute Summary collapse
-
#loser ⇒ Object
readonly
Returns the value of attribute loser.
-
#majority ⇒ Object
readonly
Returns the value of attribute majority.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#tallied_votes ⇒ Object
readonly
Returns the value of attribute tallied_votes.
Instance Method Summary collapse
- #exist_majority? ⇒ Boolean
-
#initialize(order, candidates, votes) ⇒ Round
constructor
A new instance of Round.
- #next_candidates ⇒ Object
- #next_votes ⇒ Object
Constructor Details
#initialize(order, candidates, votes) ⇒ Round
Returns a new instance of Round.
7 8 9 10 11 12 13 14 |
# File 'lib/irv/round.rb', line 7 def initialize(order, candidates, votes) @order = order @candidates = candidates @votes = votes @tallied_votes = tally(votes) @majority = calc_majority @loser = calc_loser end |
Instance Attribute Details
#loser ⇒ Object (readonly)
Returns the value of attribute loser.
5 6 7 |
# File 'lib/irv/round.rb', line 5 def loser @loser end |
#majority ⇒ Object (readonly)
Returns the value of attribute majority.
5 6 7 |
# File 'lib/irv/round.rb', line 5 def majority @majority end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
5 6 7 |
# File 'lib/irv/round.rb', line 5 def order @order end |
#tallied_votes ⇒ Object (readonly)
Returns the value of attribute tallied_votes.
5 6 7 |
# File 'lib/irv/round.rb', line 5 def tallied_votes @tallied_votes end |
Instance Method Details
#exist_majority? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/irv/round.rb', line 16 def exist_majority? return true if @majority false end |
#next_candidates ⇒ Object
22 23 24 25 26 |
# File 'lib/irv/round.rb', line 22 def next_candidates return nil if exist_majority? @candidates.reject { |candidate| candidate == @loser } end |
#next_votes ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/irv/round.rb', line 28 def next_votes return nil if exist_majority? @votes.map do |votes_in_a_rank| votes_in_a_rank.reject { |candidate| candidate == @loser } end end |