Class WWW::Mechanize::Page::Meta
In: lib/www/mechanize/page/meta.rb
Parent: Link
Mechanize\n[lib/www/mechanize.rb\nlib/www/mechanize/chain.rb\nlib/www/mechanize/chain/auth_headers.rb\nlib/www/mechanize/chain/body_decoding_handler.rb\nlib/www/mechanize/chain/connection_resolver.rb\nlib/www/mechanize/chain/custom_headers.rb\nlib/www/mechanize/chain/header_resolver.rb\nlib/www/mechanize/chain/parameter_resolver.rb\nlib/www/mechanize/chain/pre_connect_hook.rb\nlib/www/mechanize/chain/request_resolver.rb\nlib/www/mechanize/chain/response_body_parser.rb\nlib/www/mechanize/chain/response_header_handler.rb\nlib/www/mechanize/chain/response_reader.rb\nlib/www/mechanize/chain/ssl_resolver.rb\nlib/www/mechanize/chain/uri_resolver.rb\nlib/www/mechanize/content_type_error.rb\nlib/www/mechanize/cookie.rb\nlib/www/mechanize/cookie_jar.rb\nlib/www/mechanize/file.rb\nlib/www/mechanize/file_response.rb\nlib/www/mechanize/file_saver.rb\nlib/www/mechanize/form.rb\nlib/www/mechanize/form/button.rb\nlib/www/mechanize/form/check_box.rb\nlib/www/mechanize/form/field.rb\nlib/www/mechanize/form/file_upload.rb\nlib/www/mechanize/form/image_button.rb\nlib/www/mechanize/form/multi_select_list.rb\nlib/www/mechanize/form/option.rb\nlib/www/mechanize/form/radio_button.rb\nlib/www/mechanize/form/select_list.rb\nlib/www/mechanize/headers.rb\nlib/www/mechanize/history.rb\nlib/www/mechanize/monkey_patch.rb\nlib/www/mechanize/page.rb\nlib/www/mechanize/page/base.rb\nlib/www/mechanize/page/frame.rb\nlib/www/mechanize/page/link.rb\nlib/www/mechanize/page/meta.rb\nlib/www/mechanize/pluggable_parsers.rb\nlib/www/mechanize/redirect_limit_reached_error.rb\nlib/www/mechanize/redirect_not_get_or_head_error.rb\nlib/www/mechanize/response_code_error.rb\nlib/www/mechanize/unsupported_scheme_error.rb\nlib/www/mechanize/util.rb] lib/www/mechanize.rb Handler WWW dot/m_52_0.png

This class encapsulates a Meta tag. Mechanize treats meta tags just like ‘a’ tags. Meta objects will contain links, but most likely will have no text.

Methods

parse  

Constants

CONTENT_REGEXP = /^\s*(\d+\.?\d*)(;|;\s*url=\s*['"]?(\S*?)['"]?)?\s*$/i   Matches the content attribute of a meta tag. After the match:
  $1:: delay
  $3:: url

Public Class methods

Parses the delay and url from the content attribute of a meta tag. Parse requires the uri of the current page to infer a url when no url is specified. If a block is given, the parsed delay and url will be passed to it for further processing.

Returns nil if the delay and url cannot be parsed.

  # <meta http-equiv="refresh" content="5;url=http://example.com/" />
  uri = URI.parse('http://current.com/')

  Meta.parse("5;url=http://example.com/", uri)  # => ['5', 'http://example.com/']
  Meta.parse("5;url=", uri)                     # => ['5', 'http://current.com/']
  Meta.parse("5", uri)                          # => ['5', 'http://current.com/']
  Meta.parse("invalid content", uri)            # => nil

[Source]

    # File lib/www/mechanize/page/meta.rb, line 32
32:           def parse(content, uri)
33:             if content && content =~ CONTENT_REGEXP
34:               delay, url = $1, $3
35: 
36:               url = case url
37:               when nil, "" then uri.to_s
38:               when /^http/i then url
39:               else "http://#{uri.host}#{url}"
40:               end
41: 
42:               block_given? ? yield(delay, url) : [delay, url]
43:             else
44:               nil
45:             end
46:           end

[Validate]