class Empyrean::CLI
Public Class Methods
new(*argv)
click to toggle source
# File lib/empyrean/cli.rb, line 29 def initialize(*argv) @options = OptParser.parse(argv) @config = ConfigLoader.new(@options).load_config parsed = analyze_tweets print_stats(parsed) generate_html(parsed) end
Public Instance Methods
analyze_tweets()
click to toggle source
# File lib/empyrean/cli.rb, line 38 def analyze_tweets tweet_files = TweetLoader.read_directory(@options.jsondir) parsed = [] parser = TweetParser.new(@options, @config) tweet_files.each do |file| tweet = TweetLoader.read_file file parsed << parser.parse(tweet) end TweetParser.merge_parsed parsed end
generate_html(parsed)
click to toggle source
# File lib/empyrean/cli.rb, line 74 def generate_html(parsed) puts "Generating HTML" template = File.read template_file renderer = TemplateRenderer.new @config, template, parsed File.open(@options.outfile, 'w') do |outfile| outfile.write renderer.render outfile.flush end puts " => #{@options.outfile}" end
print_stats(parsed)
click to toggle source
# File lib/empyrean/cli.rb, line 49 def print_stats(parsed) puts "Analyzed #{parsed[:tweet_count]} tweets" puts " - #{(parsed[:retweet_count] * 100 / parsed[:tweet_count].to_f).round(2)}% retweets\n" return unless @options.print_stats headers = { mentions: ["You send most mentions to:", "times", :name], clients: ["Most used clients:", "tweets", :name], hashtags: ["Your most used hashtags:", "times", :hashtag], smileys: ["Your most used smileys:", "times", :smiley] } headers.each do |k, v| if @config[k][:enabled] puts v[0] begin @config[k][:top].times do |i| puts "#{sprintf "%2d", i + 1}. #{'#' if k == :hashtags}#{parsed[k][i][1][v[2]]} (#{parsed[k][i][1][:count]} #{v[1]})" end rescue => _ end end end end
template_file()
click to toggle source
# File lib/empyrean/cli.rb, line 85 def template_file if File.exist? File.join(Dir.pwd, @options.template) File.join(Dir.pwd, @options.template) elsif TemplateLister.list.include? @options.template File.join TEMPLATE_DIR, @options.template else @options.template end end