Class: Empyrean::CLI
- Inherits:
-
Object
- Object
- Empyrean::CLI
- Defined in:
- lib/empyrean/cli.rb
Instance Method Summary collapse
- #analyze_tweets ⇒ Object
- #generate_html(parsed) ⇒ Object
-
#initialize(*argv) ⇒ CLI
constructor
A new instance of CLI.
- #print_stats(parsed) ⇒ Object
- #template_file ⇒ Object
Constructor Details
#initialize(*argv) ⇒ CLI
Returns a new instance of CLI.
29 30 31 32 33 34 35 36 |
# 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 |
Instance Method Details
#analyze_tweets ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# 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) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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 ⇒ Object
85 86 87 88 89 90 91 92 93 |
# 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 |