class Ruboty::YMCrawl::HostManager
ホストごとの処理を管理するクラス
Constants
- DEFAULT_WAIT_TIME
Public Class Methods
new()
click to toggle source
# File lib/ruboty/ymcrawl/crawler.rb, line 36 def initialize @host_list = {} @wait_time = DEFAULT_WAIT_TIME end
Public Instance Methods
set_wait_time(wait_time)
click to toggle source
# File lib/ruboty/ymcrawl/crawler.rb, line 41 def set_wait_time(wait_time) @wait_time = wait_time end
wait(url)
click to toggle source
最後にアクセスした日時を取得する
# 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