Class: Pupa::VoteEvent

Inherits:
Object
  • Object
show all
Includes:
Concerns::Sourceable, Concerns::Timestamps, Model
Defined in:
lib/pupa/models/vote_event.rb

Overview

An event at which people's votes are recorded.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Sourceable

#add_source, #sources=

Methods included from Model

#==, #[], #[]=, #_id=, #add_extra, append_features, #extras=, #fingerprint, #foreign_properties, #to_h, #validate!

Constructor Details

#initialize(*args) ⇒ VoteEvent

Returns a new instance of VoteEvent.



16
17
18
19
20
# File 'lib/pupa/models/vote_event.rb', line 16

def initialize(*args)
  @group_results = []
  @counts = []
  super
end

Instance Attribute Details

#countsObject

Returns the value of attribute counts.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def counts
  @counts
end

#end_dateObject

Returns the value of attribute end_date.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def end_date
  @end_date
end

#group_resultsObject

Returns the value of attribute group_results.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def group_results
  @group_results
end

#identifierObject

Returns the value of attribute identifier.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def identifier
  @identifier
end

#legislative_session_idObject

Returns the value of attribute legislative_session_id.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def legislative_session_id
  @legislative_session_id
end

#motion_idObject

Returns the value of attribute motion_id.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def motion_id
  @motion_id
end

#organization_idObject

Returns the value of attribute organization_id.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def organization_id
  @organization_id
end

#resultObject

Returns the value of attribute result.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def result
  @result
end

#start_dateObject

Returns the value of attribute start_date.



11
12
13
# File 'lib/pupa/models/vote_event.rb', line 11

def start_date
  @start_date
end

Instance Method Details

#add_count(option, value, group: nil) ⇒ Object

Adds a count.

Parameters:

  • option (String)

    an option in a vote event

  • value (String)

    the number of votes for an option

  • group (String) (defaults to: nil)

    a group of voters



62
63
64
65
66
67
68
69
70
# 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) ⇒ Object

Adds a group result.

Parameters:

  • result (String)

    the result of the vote event within a group of voters

  • group (String) (defaults to: nil)

    a group of voters



47
48
49
50
51
52
53
54
55
# 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

#to_sString

Returns the vote event's identifier and organization ID.

Returns:

  • (String)

    the vote event's identifier and organization ID



25
26
27
# File 'lib/pupa/models/vote_event.rb', line 25

def to_s
  "#{identifier} in #{organization_id}"
end