Class: Equalshares::FixedBudget::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/equalshares/fixed_budget.rb

Overview

Collects the per-candidate explanation data produced while running the rule (money behind each candidate and its effective vote count over the rounds, plus the per-voter endowment). Kept separate from the selection logic; #to_h yields the same hash shape the callers consume.

Instance Method Summary collapse

Constructor Details

#initialize(project_ids, endowment) ⇒ Report

Returns a new instance of Report.



43
44
45
46
47
48
49
50
51
# File 'lib/equalshares/fixed_budget.rb', line 43

def initialize(project_ids, endowment)
  @endowment = endowment
  @money_behind_candidate = {}
  @effective_vote_count = {}
  project_ids.each do |c|
    @money_behind_candidate[c] = []
    @effective_vote_count[c] = []
  end
end

Instance Method Details

#record_effective_vote_count(project_id, value) ⇒ Object



57
58
59
# File 'lib/equalshares/fixed_budget.rb', line 57

def record_effective_vote_count(project_id, value)
  @effective_vote_count[project_id] << value.to_f
end

#record_money_behind(project_id, value) ⇒ Object



53
54
55
# File 'lib/equalshares/fixed_budget.rb', line 53

def record_money_behind(project_id, value)
  @money_behind_candidate[project_id] << value.to_f
end

#record_unaffordable(project_id) ⇒ Object



61
62
63
# File 'lib/equalshares/fixed_budget.rb', line 61

def record_unaffordable(project_id)
  @effective_vote_count[project_id] << 0
end

#to_hObject



65
66
67
68
69
# File 'lib/equalshares/fixed_budget.rb', line 65

def to_h
  { money_behind_candidate: @money_behind_candidate,
    effective_vote_count: @effective_vote_count,
    endowment: @endowment }
end