Class: ReplacerBot::Replacer
- Inherits:
-
Object
- Object
- ReplacerBot::Replacer
- Defined in:
- lib/replacer_bot/replacer.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize ⇒ Replacer
constructor
A new instance of Replacer.
- #save ⇒ Object
-
#search ⇒ Object
count = 20.
- #tweet(dry_run: false, chatty: false) ⇒ Object
- #tweets ⇒ Object
Constructor Details
#initialize ⇒ Replacer
Returns a new instance of Replacer.
5 6 7 8 9 |
# File 'lib/replacer_bot/replacer.rb', line 5 def initialize @config = Config.instance.config @search_term = @config.search_term @client = TwitterClient.client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/replacer_bot/replacer.rb', line 3 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/replacer_bot/replacer.rb', line 3 def config @config end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
3 4 5 |
# File 'lib/replacer_bot/replacer.rb', line 3 def results @results end |
Instance Method Details
#save ⇒ Object
36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
count = 20
11 12 13 14 15 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
17 18 19 |
# 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 |