class ReplacerBot::Replacer
Attributes
client[R]
config[R]
results[R]
Public Class Methods
new()
click to toggle source
# File lib/replacer_bot/replacer.rb, line 5 def initialize @config = Config.instance.config @search_term = @config.search_term @client = TwitterClient.client end
Public Instance Methods
save()
click to toggle source
# File lib/replacer_bot/replacer.rb, line 36 def save if search.first File.open @config.save_file, 'w' do |file| Marshal.dump search.first.id, file end end end
search()
click to toggle source
# File lib/replacer_bot/replacer.rb, line 11 def search #count = 20 @results ||= begin results = ReplacerBot.filter list: @client.search(ReplacerBot.encode(term: @search_term), lang: @config.language, result_type: 'recent').take(@config.search_count), ignore_spaces: @config.ignore_spaces end end
tweet(dry_run: false, chatty: false)
click to toggle source
# File lib/replacer_bot/replacer.rb, line 21 def tweet dry_run: false, chatty: false tweets.each_with_index do |tweet, index| puts "Tweeting: #{tweet}" if chatty @client.update tweet unless dry_run unless dry_run # unless index == tweets.count - 1 puts "Sleeping #{@config.interval} seconds" if chatty sleep @config.interval # end end end save unless dry_run end
tweets()
click to toggle source
# File lib/replacer_bot/replacer.rb, line 17 def tweets search.map { |r| ReplacerBot.truncate ReplacerBot.title_case ReplacerBot.encode_entities ReplacerBot.replace string: r.text } end