Module: TweetWatch::Utils

Included in:
CLI, Monitor
Defined in:
lib/tweet_watch/utils.rb

Instance Method Summary collapse

Instance Method Details

#escape_str(str) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tweet_watch/utils.rb', line 12

def escape_str(str)
  str2 = str.gsub('"', '\"')
  str2.gsub(/\\(.)/) do |s|
    case $1
    when "n"
      "\n"
    when "t"
      "\t"
    else
      $1
    end
  end      
end

#load_config(options) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/tweet_watch/utils.rb', line 4

def load_config(options)
  if options[:config_file]
    TweetWatch.config.load_from_path(options[:config_file])
  else
    TweetWatch.config.load_from_path("config.yml")
  end
end


33
34
35
36
37
38
# File 'lib/tweet_watch/utils.rb', line 33

def print_dm(tw)
    puts "\nDM --- DM".colorize(color: :light_white, background: :red)
    puts "#{tw.sender.name} (@#{tw.sender.screen_name})".colorize(color: :light_yellow, background: :red) + " FW: #{tw.sender.followers_count}".colorize(color: :green, background: :red)
    puts tw.text.colorize(color: :white, background: :red)
    puts "#{(Time.now - tw.created_at).round(2)} secs ago".colorize(color: :yellow, background: :red)
end


26
27
28
29
30
31
# File 'lib/tweet_watch/utils.rb', line 26

def print_tweet(tw)
    puts "\n---".colorize(:light_red)
    puts "#{tw.user.name} (@#{tw.user.screen_name})".colorize(:light_yellow) + " FW: #{tw.user.followers_count}".colorize(:green)
    puts tw.text.colorize(:light_cyan)
    puts "#{(Time.now - tw.created_at).round(2)} secs ago".colorize(:light_red) +" RT: #{tw.retweet_count} LK: #{tw.favorite_count}\n".colorize(:green)
end