class Pupa::VoteEvent
An event at which people’s votes are recorded.
Attributes
counts[RW]
end_date[RW]
group_results[RW]
identifier[RW]
legislative_session_id[RW]
motion_id[RW]
organization_id[RW]
result[RW]
start_date[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Pupa::Concerns::Sourceable::new
# File lib/pupa/models/vote_event.rb, line 16 def initialize(*args) @group_results = [] @counts = [] super end
Public Instance Methods
add_count(option, value, group: nil)
click to toggle source
Adds a count.
@param [String] option an option in a vote event @param [String] value the number of votes for an option @param [String] group a group of voters
# File lib/pupa/models/vote_event.rb, line 62 def add_count(option, value, group: nil) data = {option: option, value: value} if group data[:group] = group end if option.present? && value.present? @counts << data end end
add_group_result(result, group: nil)
click to toggle source
Adds a group result.
@param [String] result the result of the vote event within a group of voters @param [String] group a group of voters
# File lib/pupa/models/vote_event.rb, line 47 def add_group_result(result, group: nil) data = {result: result} if group data[:group] = group end if result.present? @group_results << data end end
counts=(counts)
click to toggle source
Sets the counts.
@param [Array] counts a list of counts
# File lib/pupa/models/vote_event.rb, line 39 def counts=(counts) @counts = symbolize_keys(counts) end
group_results=(group_results)
click to toggle source
Sets the group results.
@param [Array] group_results
a list of group results
# File lib/pupa/models/vote_event.rb, line 32 def group_results=(group_results) @group_results = symbolize_keys(group_results) end
to_s()
click to toggle source
Returns the vote event’s identifier and organization ID.
@return [String] the vote event’s identifier and organization ID
# File lib/pupa/models/vote_event.rb, line 25 def to_s "#{identifier} in #{organization_id}" end