Class: RTBot
- Inherits:
-
Object
- Object
- RTBot
- Defined in:
- lib/rtbot.rb
Instance Method Summary collapse
-
#initialize(yaml_file_path) ⇒ RTBot
constructor
A new instance of RTBot.
- #run! ⇒ Object
- #test_run ⇒ Object
Constructor Details
#initialize(yaml_file_path) ⇒ RTBot
Returns a new instance of RTBot.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rtbot.rb', line 6 def initialize(yaml_file_path) @config = YAML.load(File.read(yaml_file_path)) @config['last_id_path'] = File.dirname(yaml_file_path) + "/" + File.basename(yaml_file_path, File.extname(yaml_file_path)) + ".last_id" unless @config['last_id_path'] @config['log_path'] = File.dirname(yaml_file_path) + "/" + File.basename(yaml_file_path, File.extname(yaml_file_path)) + ".log" unless @config['log_path'] if File.exists?(@config['last_id_path']) @last_read_id = File.new(@config['last_id_path'], 'r').gets else @last_read_id = 1 end end |
Instance Method Details
#run! ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rtbot.rb', line 32 def run! @log = File.new(@config['log_path'], 'a') tweet authenticate, search @log.close end |
#test_run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rtbot.rb', line 19 def test_run log = File.new(@config['log_path'], 'a') log.puts "Test run at #{Time.now}" search.each do | tweet | log.puts tweet_text = "RT @#{tweet.from_user}: #{tweet.text}".first(139) end log.close end |