Class: Mechanize::Chain::ResponseBodyParser
- Inherits:
-
Object
- Object
- Mechanize::Chain::ResponseBodyParser
- Includes:
- Handler
- Defined in:
- lib/mechanize/chain/response_body_parser.rb
Instance Attribute Summary
Attributes included from Handler
Instance Method Summary collapse
- #handle(ctx, params) ⇒ Object
-
#initialize(pluggable_parser, watch_for_set) ⇒ ResponseBodyParser
constructor
A new instance of ResponseBodyParser.
Constructor Details
#initialize(pluggable_parser, watch_for_set) ⇒ ResponseBodyParser
Returns a new instance of ResponseBodyParser.
6 7 8 9 |
# File 'lib/mechanize/chain/response_body_parser.rb', line 6 def initialize(pluggable_parser, watch_for_set) @pluggable_parser = pluggable_parser @watch_for_set = watch_for_set end |
Instance Method Details
#handle(ctx, params) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mechanize/chain/response_body_parser.rb', line 11 def handle(ctx, params) response = params[:response] response_body = params[:response_body] uri = params[:uri] content_type = nil unless response['Content-Type'].nil? data = response['Content-Type'].match(/^([^;]*)/) content_type = data[1].downcase.split(',')[0] unless data.nil? end # Find our pluggable parser params[:page] = @pluggable_parser.parser(content_type).new( uri, response, response_body, response.code ) { |parser| parser.mech = params[:agent] if parser.respond_to? :mech= if parser.respond_to?(:watch_for_set=) && @watch_for_set parser.watch_for_set = @watch_for_set end } super end |