class Spidr::Page

Represents a requested page from a website.

Attributes

headers[R]

Headers returned with the body

response[R]

HTTP Response

url[R]

URL of the page

Public Class Methods

new(url,response) click to toggle source

Creates a new Page object.

@param [URI::HTTP] url

The URL of the page.

@param [Net::HTTP::Response] response

The response from the request for the page.
# File lib/spidr/page.rb, line 33
def initialize(url,response)
  @url      = url
  @response = response
  @headers  = response.to_hash
  @doc      = nil
end

Public Instance Methods

is_redirect?() click to toggle source

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.

@return [Boolean]

Specifies whether the response code is a HTTP Redirect code.
# File lib/spidr/page.rb, line 65
def is_redirect?
  case code
  when 300..303, 307
    true
  when 200
    meta_redirect?
  else
    false
  end
end
Also aliased as: redirect?
meta_redirect() click to toggle source

The meta-redirect links of the page.

@return [Array<String>]

All meta-redirect links in the page.

@deprecated

Deprecated in 0.3.0 and will be removed in 0.4.0.
Use {#meta_redirects} instead.
# File lib/spidr/page.rb, line 50
def meta_redirect
  STDERR.puts 'DEPRECATION: Spidr::Page#meta_redirect will be removed in 0.3.0'
  STDERR.puts 'DEPRECATION: Use Spidr::Page#meta_redirects instead'

  meta_redirects
end
redirect?()
Alias for: is_redirect?

Protected Instance Methods

method_missing(name,*arguments,&block) click to toggle source

Provides transparent access to the values in {#headers}.

@param [Symbol] name

The name of the missing method.

@param [Array] arguments

Additional arguments for the missing method.

@return [String]

The missing method mapped to a header in {#headers}.

@raise [NoMethodError]

The missing method did not map to a header in {#headers}.
Calls superclass method
# 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