class Empyrean::TemplateRenderer
Public Class Methods
new(config, template, parsed_tweets)
click to toggle source
Initializes a new TemplateRenderer
.
template: The template to use (i.e. not the file name) parsed_tweets: The dict that gets returned by TweetParser::merge_parsed
# File lib/empyrean/templaterenderer.rb, line 30 def initialize(config, template, parsed_tweets) @config = config @template = template @parsed = parsed_tweets end
Public Instance Methods
render()
click to toggle source
Renders @template.
# File lib/empyrean/templaterenderer.rb, line 38 def render mentions = mentions_erb hashtags = hashtags_erb smileys = smileys_erb clients = clients_erb counters = { tweets: @parsed[:tweet_count], retweets: @parsed[:retweet_count], retweets_percentage: (@parsed[:retweet_count] * 100 / @parsed[:tweet_count].to_f).round(2), selftweets: @parsed[:selftweet_count], selftweets_percentage: (@parsed[:selftweet_count] * 100 / @parsed[:tweet_count].to_f).round(2) } times_of_day = times_erb erb = ERB.new @template erb.result binding end
Private Instance Methods
clients_erb()
click to toggle source
Returns an array with the clients which can be easily used within ERB.
# File lib/empyrean/templaterenderer.rb, line 139 def clients_erb retdict = { enabled: @config[:clients][:enabled], top: [], nottop: [] } if @config[:clients][:enabled] top = @parsed[:clients].slice(0, @config[:clients][:top]) # top X clients top.each do |client| retdict[:top] << { name: client[1][:name], url: client[1][:url], count: client[1][:count], percentage: (client[1][:count] * 100 / @parsed[:tweet_count].to_f).round(2) } end nottop = @parsed[:clients].slice(@config[:clients][:top], @config[:clients][:notop]) # not in the top X unless nottop.nil? nottop.each do |client| client[1].delete(:example) retdict[:nottop] << { name: client[1][:name], url: client[1][:url], count: client[1][:count], percentage: (client[1][:count] * 100 / @parsed[:tweet_count].to_f).round(2) } end end end retdict end
mentions_erb()
click to toggle source
Returns an array with the mentions which can be easily used within ERB.
# File lib/empyrean/templaterenderer.rb, line 58 def mentions_erb retdict = { enabled: @config[:mentions][:enabled], top: [], nottop: [] } if @config[:mentions][:enabled] top = @parsed[:mentions].slice(0, @config[:mentions][:top]) # top X mentions top.each do |mention| retdict[:top] << mention[1] end nottop = @parsed[:mentions].slice(@config[:mentions][:top], @config[:mentions][:notop]) # not in the top X unless nottop.nil? nottop.each do |mention| mention[1].delete(:example) retdict[:nottop] << mention[1] end end end retdict end
smileys_erb()
click to toggle source
Returns an array with the smileys which can be easily used within ERB.
# File lib/empyrean/templaterenderer.rb, line 112 def smileys_erb retdict = { enabled: @config[:smileys][:enabled], top: [], nottop: [] } if @config[:smileys][:enabled] top = @parsed[:smileys].slice(0, @config[:smileys][:top]) # top X smileys top.each do |smiley| retdict[:top] << smiley[1] end nottop = @parsed[:smileys].slice(@config[:smileys][:top], @config[:smileys][:notop]) # not in the top X unless nottop.nil? nottop.each do |smiley| smiley[1].delete(:example) retdict[:nottop] << smiley[1] end end end retdict end
times_erb()
click to toggle source
# File lib/empyrean/templaterenderer.rb, line 174 def times_erb retarr = [] max_count = @parsed[:times_of_day].max @parsed[:times_of_day].each do |count| retarr << { count: count, percentage: (count * 100 / @parsed[:tweet_count].to_f).round(1), size: ((count / max_count.to_f) * 100).to_i, max: count == max_count } end retarr end