Class: W3map::Bot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Bot

Returns a new instance of Bot.



113
114
115
116
117
118
119
# File 'lib/w3map.rb', line 113

def initialize(session)
  @session = session
  @http_engine = HttpEngine.new(self)
  # TODO: create class NeuronStack (NeuronPipeline?)
  @neurons = []
  @neurons << Neurons::SimpleCrawler.new(self)
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



112
113
114
# File 'lib/w3map.rb', line 112

def session
  @session
end

Instance Method Details

#startObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/w3map.rb', line 120

def start
  loop do
    puts "Bot waiting for task (#{Time.now})"
    url = @session.queue.pop
    # break if url.nil?
    puts "PROCESS #{url}"
    response = @http_engine.response_for(url)
    # save url, 'response-code', response.code
    data = {'response-code' => response.code}
    @neurons.each { |neuron| neuron.process url, response, data } #TODO: use NeuronStack or other
    @session.dstore.save_hash url, data
  end
rescue SignalException => e
  puts
end

#stopObject



135
136
137
# File 'lib/w3map.rb', line 135

def stop
  # @session.close ?
end