Class: TallyGem::Printers::BBCode

Inherits:
Object
  • Object
show all
Defined in:
lib/tallygem/printers/bbcode.rb

Class Method Summary collapse

Class Method Details

.render(tally, compact: false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tallygem/printers/bbcode.rb', line 8

def render(tally, compact: false)
  output = []
  output << tally.quest.to_s
  output << invisitext("##### TallyGem v#{TallyGem::VERSION}")
  tally.result.each_with_index do |(task, votes), idx|
    sb = []
    sb << horizontal_rule('---------------------------------------------------') + "\n" if idx > 0
    sb << bold("Task: #{task}") + "\n" if task
    votes = votes.sort_by { |_, v| v[:posts].size }.reverse!
    votes.each do |_, vote|
      sb << Common.render_vote(vote[:vote])
      sb << bold("Number of voters: #{vote[:posts].size}")
      sb << vote[:posts].collect { |p| post_link(p.author, p.id) }.join(', ') unless compact
      sb.last << "\n"
    end
    output << sb.join("\n")
  end
  output << "\n" + "Total number of voters: #{tally.total_voters}"
  output.join "\n"
end