Class: WebCrawler::Handler

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

Direct Known Subclasses

HandlerParser

Instance Method Summary collapse

Constructor Details

#initialize(*responses_or_request, &handler) ⇒ Handler

Returns a new instance of Handler.



5
6
7
8
9
10
11
12
# File 'lib/web_crawler/handler.rb', line 5

def initialize(*responses_or_request, &handler)
  @handler = handler
  if responses_or_request.first.is_a?(BatchRequest)
    @target = responses_or_request.first
  else
    @target = responses_or_request.flatten
  end
end

Instance Method Details

#processObject



14
15
16
17
18
# File 'lib/web_crawler/handler.rb', line 14

def process
  @result ||= @target.map do |response|
    @handler.call(response, @target)
  end
end