Class: Equalshares::Pabulib::VoteRowParser
- Inherits:
-
Object
- Object
- Equalshares::Pabulib::VoteRowParser
- Defined in:
- lib/equalshares/pabulib/vote_row_parser.rb
Overview
Parses a single row of the VOTES section into the accumulator, turning the vote into approvals and (for scoring/cumulative/ordinal ballots) per-voter scores.
Instance Method Summary collapse
-
#initialize(accumulator) ⇒ VoteRowParser
constructor
A new instance of VoteRowParser.
- #parse(row, header, line_number) ⇒ Object
Constructor Details
#initialize(accumulator) ⇒ VoteRowParser
Returns a new instance of VoteRowParser.
8 9 10 11 12 13 |
# File 'lib/equalshares/pabulib/vote_row_parser.rb', line 8 def initialize(accumulator) @acc = accumulator vote_type = accumulator.["vote_type"] @cardinal = CARDINAL_VOTE_TYPES.include?(vote_type) @ordinal = vote_type == "ordinal" end |
Instance Method Details
#parse(row, header, line_number) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/equalshares/pabulib/vote_row_parser.rb', line 15 def parse(row, header, line_number) voter_id_idx = header.index("voter_id") vote_idx = header.index("vote") points_idx = header.index("points") require_columns!(voter_id_idx, vote_idx, line_number) validate_column_count!(row, header, line_number) voter_id = row[voter_id_idx].strip raise ParseError, "Line #{line_number}: Duplicate voter ID '#{voter_id}' found." if @acc.voter_ids_set[voter_id] record_vote(row, vote_idx, points_idx, voter_id, line_number) store_voter(row, header, voter_id) end |