Class: Ruboty::YMCrawl::HostManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ruboty/ymcrawl/crawler.rb

Overview

ホストごとの処理を管理するクラス

Constant Summary collapse

DEFAULT_WAIT_TIME =
2

Instance Method Summary collapse

Constructor Details

#initializeHostManager

Returns a new instance of HostManager.



36
37
38
39
# File 'lib/ruboty/ymcrawl/crawler.rb', line 36

def initialize
  @host_list = {}
  @wait_time = DEFAULT_WAIT_TIME
end

Instance Method Details

#set_wait_time(wait_time) ⇒ Object



41
# File 'lib/ruboty/ymcrawl/crawler.rb', line 41

def set_wait_time(wait_time) @wait_time = wait_time end

#wait(url) ⇒ Object

最後にアクセスした日時を取得する



44
45
46
47
48
49
50
51
# File 'lib/ruboty/ymcrawl/crawler.rb', line 44

def wait(url)
  host = URI( URLUtil.normalize_url(url) ).host
  unless @host_list[host] == nil then
    time_diff = Time.now - @host_list[host]
    puts "sleep: #{sleep(@wait_time - time_diff)}sec." if time_diff < @wait_time
  end
  @host_list[host] = Time.now
end