Class: Spidr::Page
- Inherits:
-
Object
- Object
- Spidr::Page
- Defined in:
- lib/spidr/page.rb
Overview
Represents a requested page from a website.
Constant Summary
Constants included from Headers
Headers::RESERVED_COOKIE_NAMES
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Headers returned with the body.
-
#response ⇒ Object
readonly
HTTP Response.
-
#url ⇒ Object
readonly
URL of the page.
Instance Method Summary collapse
-
#initialize(url, response) ⇒ Page
constructor
Creates a new Page object.
-
#is_redirect? ⇒ Boolean
(also: #redirect?)
Determines if the response code is
300
,301
,302
,303
or307
. -
#meta_redirect ⇒ Array<String>
deprecated
Deprecated.
Deprecated in 0.3.0 and will be removed in 0.4.0. Use Links#meta_redirects instead.
-
#method_missing(name, *arguments, &block) ⇒ String
protected
Provides transparent access to the values in #headers.
Methods included from Links
#each_link, #each_meta_redirect, #each_redirect, #each_url, #links, #meta_redirect?, #meta_redirects, #redirects_to, #to_absolute, #urls
Methods included from Body
#at, #body, #doc, #search, #title
Methods included from Headers
#atom?, #bad_request?, #code, #content_type, #content_types, #cookie, #cookie_params, #cookies, #css?, #directory?, #had_internal_server_error?, #html?, #is_content_type?, #is_forbidden?, #is_missing?, #is_ok?, #is_unauthorized?, #javascript?, #json?, #ms_word?, #pdf?, #plain_text?, #rss?, #timedout?, #xml?, #xsl?, #zip?
Constructor Details
#initialize(url, response) ⇒ Page
Creates a new Page object.
33 34 35 36 37 38 |
# File 'lib/spidr/page.rb', line 33 def initialize(url,response) @url = url @response = response @headers = response.to_hash @doc = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, &block) ⇒ String (protected)
Provides transparent access to the values in #headers.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/spidr/page.rb', line 95 def method_missing(name,*arguments,&block) if (arguments.empty? && block.nil?) header_name = name.to_s.sub('_','-') if @response.key?(header_name) return @response[header_name] end end return super(name,*arguments,&block) end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Headers returned with the body
22 23 24 |
# File 'lib/spidr/page.rb', line 22 def headers @headers end |
#response ⇒ Object (readonly)
HTTP Response
19 20 21 |
# File 'lib/spidr/page.rb', line 19 def response @response end |
#url ⇒ Object (readonly)
URL of the page
16 17 18 |
# File 'lib/spidr/page.rb', line 16 def url @url end |
Instance Method Details
#is_redirect? ⇒ Boolean Also known as: redirect?
Determines if the response code is 300
, 301
, 302
, 303
or 307
. Also checks for "soft" redirects added at the page
level by a meta refresh tag.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/spidr/page.rb', line 65 def is_redirect? case code when 300..303, 307 true when 200 else false end end |
#meta_redirect ⇒ Array<String>
Deprecated in 0.3.0 and will be removed in 0.4.0. Use Links#meta_redirects instead.
The meta-redirect links of the page.
50 51 52 53 54 55 |
# File 'lib/spidr/page.rb', line 50 def STDERR.puts 'DEPRECATION: Spidr::Page#meta_redirect will be removed in 0.3.0' STDERR.puts 'DEPRECATION: Use Spidr::Page#meta_redirects instead' end |