class Mechanize::Chain::ResponseBodyParser

Public Class Methods

new(pluggable_parser, watch_for_set) click to toggle source
# 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

Public Instance Methods

handle(ctx, params) click to toggle source
Calls superclass method Mechanize::Handler#handle
# 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
  parser_klass = @pluggable_parser.parser(content_type)
  params[:page] = parser_klass.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