| Class | Mechanize::Page::Meta |
| In: |
lib/mechanize/page/meta.rb
|
| Parent: | Link |
| 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 |
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
# File lib/mechanize/page/meta.rb, line 31
31: def parse(content, uri)
32: if content && content =~ CONTENT_REGEXP
33: delay, url = $1, $3
34:
35: url = case url
36: when nil, "" then uri.to_s
37: when /^http/i then url
38: else "http://#{uri.host}#{url}"
39: end
40:
41: block_given? ? yield(delay, url) : [delay, url]
42: else
43: nil
44: end
45: end