Class: TallyGem::Tally
- Inherits:
-
Object
- Object
- TallyGem::Tally
- Defined in:
- lib/tallygem/tally.rb
Instance Attribute Summary collapse
-
#quest ⇒ Object
readonly
Returns the value of attribute quest.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#total_voters ⇒ Object
readonly
Returns the value of attribute total_voters.
Instance Method Summary collapse
-
#initialize(quest, partitioner = Partitions::Block) ⇒ Tally
constructor
A new instance of Tally.
-
#run ⇒ Object
TODO: Plans and nominations.
Constructor Details
#initialize(quest, partitioner = Partitions::Block) ⇒ Tally
Returns a new instance of Tally.
46 47 48 49 50 51 |
# File 'lib/tallygem/tally.rb', line 46 def initialize(quest, partitioner = Partitions::Block) @quest = quest @result = nil @total_voters = 0 @partitioner = partitioner end |
Instance Attribute Details
#quest ⇒ Object (readonly)
Returns the value of attribute quest.
44 45 46 |
# File 'lib/tallygem/tally.rb', line 44 def quest @quest end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
44 45 46 |
# File 'lib/tallygem/tally.rb', line 44 def result @result end |
#total_voters ⇒ Object (readonly)
Returns the value of attribute total_voters.
44 45 46 |
# File 'lib/tallygem/tally.rb', line 44 def total_voters @total_voters end |
Instance Method Details
#run ⇒ Object
TODO: Plans and nominations
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tallygem/tally.rb', line 54 def run return @result unless @result.nil? # remove any posts that don't have votes posts = @quest.posts.reject { |p| p.votes.empty? } # filter so that only the latest vote post by the author exists = {} posts.each do |post| if !.key?(post.) || post.id > [post.].id [post.] = post end end @total_voters = .size posts = .values @result = posts.each_with_object({}) do |post, counts| @partitioner.split(post.votes).each do |vote| nws = squash_and_clean(vote) task = vote[:task] counts[task] ||= {} counts[task][nws] ||= { vote: vote, posts: [] } counts[task][nws][:posts] << post end end end |