Class: ReplacerBot::Replacer
- Inherits:
-
Object
- Object
- ReplacerBot::Replacer
- Defined in:
- lib/replacer_bot/replacer.rb
Instance Attribute Summary collapse
-
#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(count = 20) ⇒ Object
- #tweet ⇒ 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
#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
32 33 34 35 36 37 38 |
# File 'lib/replacer_bot/replacer.rb', line 32 def save if search.first File.open @config.save_file, 'w' do |file| Marshal.dump search.first.id, file end end end |
#search(count = 20) ⇒ Object
11 12 13 14 15 |
# File 'lib/replacer_bot/replacer.rb', line 11 def search count = 20 @results ||= begin results = ReplacerBot.filter @client.search(ReplacerBot.encode(@search_term), result_type: 'recent').take(count) end end |
#tweet ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/replacer_bot/replacer.rb', line 21 def tweet tweets.each do |tweet| puts "Tweeting: #{tweet}" @client.update tweet puts "Sleeping #{@config.interval} seconds" sleep @config.interval end save end |
#tweets ⇒ Object
17 18 19 |
# File 'lib/replacer_bot/replacer.rb', line 17 def tweets search.map { |r| ReplacerBot.truncate ReplacerBot.replace r.text } end |