lib/spidr/page.rb in spidr-0.2.2 vs lib/spidr/page.rb in spidr-0.2.3
- old
+ new
@@ -3,10 +3,13 @@
require 'set'
require 'uri'
require 'nokogiri'
module Spidr
+ #
+ # Represents a requested page from a website.
+ #
class Page
# Reserved names used within Cookie strings
RESERVED_COOKIE_NAMES = Set['path', 'expires', 'domain']
@@ -44,94 +47,94 @@
def code
@response.code.to_i
end
#
- # Determines if the response code is +200+.
+ # Determines if the response code is `200`.
#
# @return [Boolean]
- # Specifies whether the response code is +200+.
+ # Specifies whether the response code is `200`.
#
def is_ok?
code == 200
end
alias ok? is_ok?
#
- # Determines if the response code is +301+ or +307+.
+ # Determines if the response code is `301` or `307`.
#
# @return [Boolean]
- # Specifies whether the response code is +301+ or +307+.
+ # Specifies whether the response code is `301` or `307`.
#
def is_redirect?
(code == 301 || code == 307)
end
alias redirect? is_redirect?
#
- # Determines if the response code is +308+.
+ # Determines if the response code is `308`.
#
# @return [Boolean]
- # Specifies whether the response code is +308+.
+ # Specifies whether the response code is `308`.
#
def timedout?
code == 308
end
#
- # Determines if the response code is +400+.
+ # Determines if the response code is `400`.
#
# @return [Boolean]
- # Specifies whether the response code is +400+.
+ # Specifies whether the response code is `400`.
#
def bad_request?
code == 400
end
#
- # Determines if the response code is +401+.
+ # Determines if the response code is `401`.
#
# @return [Boolean]
- # Specifies whether the response code is +401+.
+ # Specifies whether the response code is `401`.
#
def is_unauthorized?
code == 401
end
alias unauthorized? is_unauthorized?
#
- # Determines if the response code is +403+.
+ # Determines if the response code is `403`.
#
# @return [Boolean]
- # Specifies whether the response code is +403+.
+ # Specifies whether the response code is `403`.
#
def is_forbidden?
code == 403
end
alias forbidden? is_forbidden?
#
- # Determines if the response code is +404+.
+ # Determines if the response code is `404`.
#
# @return [Boolean]
- # Specifies whether the response code is +404+.
+ # Specifies whether the response code is `404`.
#
def is_missing?
code == 404
end
alias missing? is_missing?
#
- # Determines if the response code is +500+.
+ # Determines if the response code is `500`.
#
# @return [Boolean]
- # Specifies whether the response code is +500+.
+ # Specifies whether the response code is `500`.
#
def had_internal_server_error?
code == 500
end
@@ -304,16 +307,18 @@
# @since 0.2.2
#
def cookie_params
params = {}
- cookies.each do |key_value|
- key, value = key_value.split('=',2)
+ cookies.each do |cookie|
+ cookie.split('; ').each do |key_value|
+ key, value = key_value.split('=',2)
- next if RESERVED_COOKIE_NAMES.include?(key)
+ next if RESERVED_COOKIE_NAMES.include?(key)
- params[key] = (value || '')
+ params[key] = (value || '')
+ end
end
return params
end
@@ -330,11 +335,11 @@
#
# Returns a parsed document object for HTML, XML, RSS and Atom pages.
#
# @return [Nokogiri::HTML::Document, Nokogiri::XML::Document, nil]
# The document that represents HTML or XML pages.
- # Returns +nil+ if the page is neither HTML, XML, RSS, Atom or if
+ # Returns `nil` if the page is neither HTML, XML, RSS, Atom or if
# the page could not be parsed properly.
#
# @see http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/Document.html
# @see http://nokogiri.rubyforge.org/nokogiri/Nokogiri/HTML/Document.html
#
@@ -378,11 +383,11 @@
#
# Searches for the first occurrence an XPath or CSS Path expression.
#
# @return [Nokogiri::HTML::Node, Nokogiri::XML::Node, nil]
- # The first matched node. Returns +nil+ if no nodes could be matched,
+ # The first matched node. Returns `nil` if no nodes could be matched,
# or if the page is not a HTML or XML document.
#
# @example
# page.at('//title')
#
@@ -414,11 +419,11 @@
#
# The links from within the page.
#
# @return [Array<String>]
# All links within the HTML page, frame/iframe source URLs and any
- # links in the +Location+ header.
+ # links in the `Location` header.
#
def links
urls = []
add_url = lambda { |url|
@@ -500,10 +505,10 @@
end
protected
#
- # Provides transparent access to the values in +headers+.
+ # Provides transparent access to the values in `headers`.
#
def method_missing(sym,*args,&block)
if (args.empty? && block.nil?)
name = sym.id2name.sub('_','-')