Class: TWSS::TweetCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/twss/tweet_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/twss/tweet_collector.rb', line 7

def filename
  @filename
end

#limitObject (readonly)

Returns the value of attribute limit.



7
8
9
# File 'lib/twss/tweet_collector.rb', line 7

def limit
  @limit
end

#searchObject (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

#runObject



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