Class: TWSS::TweetCollector
- Inherits:
-
Object
- Object
- TWSS::TweetCollector
- Defined in:
- lib/twss/tweet_collector.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
Instance Method Summary collapse
-
#initialize(search, filename, limit = 1500) ⇒ TweetCollector
constructor
A new instance of TweetCollector.
- #run ⇒ Object
Constructor Details
#initialize(search, filename, limit = 1500) ⇒ TweetCollector
Returns a new instance of TweetCollector.
9 10 11 |
# File 'lib/twss/tweet_collector.rb', line 9 def initialize(search, filename, limit = 1500) @search, @filename, @limit = search, filename, limit end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/twss/tweet_collector.rb', line 7 def filename @filename end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
7 8 9 |
# File 'lib/twss/tweet_collector.rb', line 7 def limit @limit end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
7 8 9 |
# File 'lib/twss/tweet_collector.rb', line 7 def search @search end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/twss/tweet_collector.rb', line 13 def run o = File.open(filename, 'a') page, per_page = 1, 100 begin Twitter::Search.new.containing(search).per_page(per_page).page(page).each do |tweet| puts tweet.text o.puts tweet.text end page += 1 sleep 2 end while page * per_page < limit o.close end |