class TallyGem::Printers::BBCode
Public Class Methods
render(tally, compact: false)
click to toggle source
# 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
Private Class Methods
bold(str)
click to toggle source
# File lib/tallygem/printers/bbcode.rb, line 31 def bold(str) "[b]#{str}[/b]" end
horizontal_rule(str)
click to toggle source
# File lib/tallygem/printers/bbcode.rb, line 39 def horizontal_rule(str) "[hr]#{str}[/hr]" end
invisitext(str)
click to toggle source
# File lib/tallygem/printers/bbcode.rb, line 59 def invisitext(str) "[color=transparent]#{str}[/color]" end
italic(str)
click to toggle source
# File lib/tallygem/printers/bbcode.rb, line 35 def italic(str) "[i]#{str}[/i]" end
post_link(str, id)
click to toggle source
# File lib/tallygem/printers/bbcode.rb, line 55 def post_link(str, id) "[post=#{id}]#{str}[/post]" end
spoiler(str, name = nil)
click to toggle source
# File lib/tallygem/printers/bbcode.rb, line 43 def spoiler(str, name = nil) if name.nil? "[spoiler]\n#{str}\n[/spoiler]" else "[spoiler=\"#{name}\"]\n#{str}\n[/spoiler]" end end
url(str, link)
click to toggle source
# File lib/tallygem/printers/bbcode.rb, line 51 def url(str, link) "[url=\"#{link}\"]#{str}[/url]" end