Class: Pork::Crawler

Inherits:
Object
  • Object
show all
Defined in:
lib/pork_sandwich/crawler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(users = [], depth = 0, crawl_type = nil, count = nil) ⇒ Crawler

Returns a new instance of Crawler.



4
5
6
7
8
9
10
# File 'lib/pork_sandwich/crawler.rb', line 4

def initialize(users = [], depth = 0, crawl_type = nil, count = nil)
  @depth = depth
  @crawl_type = crawl_type_str_to_proc(crawl_type)
  @users = users
  @count = count

end

Instance Attribute Details

#crawl_typeObject

Returns the value of attribute crawl_type.



3
4
5
# File 'lib/pork_sandwich/crawler.rb', line 3

def crawl_type
  @crawl_type
end

#depthObject

Returns the value of attribute depth.



3
4
5
# File 'lib/pork_sandwich/crawler.rb', line 3

def depth
  @depth
end

#usersObject

Returns the value of attribute users.



3
4
5
# File 'lib/pork_sandwich/crawler.rb', line 3

def users
  @users
end

Instance Method Details

#append(user, user_info = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pork_sandwich/crawler.rb', line 40

def append(user,  = nil)
  user_search_args = @users.collect do |u|
    u.search
  end
  unless user_search_args.include?(user)
    if user.class == String
      @user = Pork::TwitterUser.new(:crawled => false, :twitter_screen_name => user)          
    else
      @user = Pork::TwitterUser.new(:crawled => false, :twitter_id => user)
    end
    if 
      @user. =  
    end
 
    @users << @user 
  end
end

#crawl(search_query = nil) ⇒ Object

crawl type = RT_TO_USER_CRAWL, RT_FROM_USER_CRAWL, ‘mention_to_user’ ‘mention_from_user’, ‘reply_to_user’, ‘reply_from_user’,



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pork_sandwich/crawler.rb', line 18

def crawl(search_query = nil)
  unless @users.empty?
    while @depth > 0
      @users.dup.each do |user|
        unless user.crawled?
          @crawl_type.call(user, search_query, @count)
          @users.each do |u|
            if u.search == user
            u.crawled = true
          end
        end
      end
    end
    @depth -= 1
  end
  else
    @crawl_type.call(nil,search_query, @count)
  end
  @users  # .collect { |u| u.search }
end

#crawl_type_str_to_proc(str) ⇒ Object



12
13
14
15
# File 'lib/pork_sandwich/crawler.rb', line 12

def crawl_type_str_to_proc(str)
  proc_dict = {'followers' => FOLLOWERS_CRAWL, 'friends' => FRIENDS_CRAWL, 'follower_ids' => FOLLOWER_IDS_CRAWL, 'friend_ids' => FRIEND_IDS_CRAWL}
  proc_dict[str]
end