lib/anemone/page.rb in anemone-0.0.6 vs lib/anemone/page.rb in anemone-0.1.0
- old
+ new
@@ -7,16 +7,16 @@
# The URL of the page
attr_reader :url
# Array of distinct A tag HREFs from the page
attr_reader :links
- #Content-type of the HTTP response
- attr_reader :content_type
+ # Headers of the HTTP response
+ attr_reader :headers
- #OpenStruct for user-stored data
+ # OpenStruct for user-stored data
attr_accessor :data
- #Nokogiri document for the HTML body
+ # Nokogiri document for the HTML body
attr_accessor :doc
# Integer response code of the page
attr_accessor :code
# Array of redirect-aliases for the page
attr_accessor :aliases
@@ -37,23 +37,23 @@
aka = nil
if !url.eql?(location)
aka = location
end
- return Page.new(url, response.body, code, response['Content-Type'], aka)
+ return Page.new(url, response.body, code, response.to_hash, aka)
rescue
return Page.new(url)
end
end
#
# Create a new page
#
- def initialize(url, body = nil, code = nil, content_type = nil, aka = nil)
+ def initialize(url, body = nil, code = nil, headers = nil, aka = nil)
@url = url
@code = code
- @content_type = content_type
+ @headers = headers
@links = []
@aliases = []
@data = OpenStruct.new
@aliases << aka if !aka.nil?
@@ -115,9 +115,16 @@
#
def links_and_their_aliases(page_hash)
@links.inject([]) do |results, link|
results.concat([link].concat(page_hash[link].aliases))
end
+ end
+
+ #
+ # The content-type returned by the HTTP request for this page
+ #
+ def content_type
+ @headers['content-type'][0] rescue nil
end
#
# Returns +true+ if the page is a HTML document, returns +false+
# otherwise.