Module: Equalshares::Pabulib
- Defined in:
- lib/equalshares/pabulib.rb,
lib/equalshares/pabulib/csv.rb,
lib/equalshares/pabulib/parser.rb,
lib/equalshares/pabulib/writer.rb,
lib/equalshares/pabulib/vote_row_parser.rb,
lib/equalshares/pabulib/project_row_parser.rb
Overview
Reads and writes pabulib (.pb) files: a sectioned, semicolon-delimited CSV with META / PROJECTS / VOTES sections. Faithful port of js/pabulibParser.js, extended to cardinal (scoring/cumulative) and ordinal ballots.
This module is a thin facade; the work lives in Pabulib::Parser (which delegates rows to Pabulib::ProjectRowParser / Pabulib::VoteRowParser) and Pabulib::Writer.
Defined Under Namespace
Modules: Csv, Writer Classes: Accumulator, Parser, ProjectRowParser, VoteRowParser
Constant Summary collapse
- SECTIONS =
%w[meta projects votes].freeze
- CARDINAL_VOTE_TYPES =
vote_type values that carry per-voter cardinal scores (a
pointscolumn). %w[scoring cumulative].freeze
- SCORED_VOTE_TYPES =
vote_type values that produce per-voter utilities (scores) for the general MES: cardinal ballots plus ordinal ballots (via Borda scores).
%w[scoring cumulative ordinal].freeze
Class Method Summary collapse
- .parse_file(path) ⇒ Object
-
.parse_from_string(filetext) ⇒ Object
Returns an Equalshares::Instance.
- .write_file(instance, path) ⇒ Object
- .write_string(instance) ⇒ Object
Class Method Details
.parse_file(path) ⇒ Object
26 27 28 |
# File 'lib/equalshares/pabulib.rb', line 26 def parse_file(path) parse_from_string(File.read(path)) end |
.parse_from_string(filetext) ⇒ Object
Returns an Equalshares::Instance.
31 32 33 |
# File 'lib/equalshares/pabulib.rb', line 31 def parse_from_string(filetext) Parser.new.parse(filetext) end |
.write_file(instance, path) ⇒ Object
39 40 41 |
# File 'lib/equalshares/pabulib.rb', line 39 def write_file(instance, path) Writer.write_file(instance, path) end |
.write_string(instance) ⇒ Object
35 36 37 |
# File 'lib/equalshares/pabulib.rb', line 35 def write_string(instance) Writer.write_string(instance) end |