sets Microformats2::Parser#http_headers on initialize

This commit is contained in:
Jessica Dillon & Jessica Lynn Suttles 2013-07-01 16:47:28 -07:00
parent ed2f66002e
commit 78df1dc8bc

View file

@ -2,13 +2,17 @@ module Microformats2
class Parser
attr_reader :http_headers, :http_body
def parse(html, headers={})
def initialize
@http_headers = {}
end
def parse(html, headers=@http_headers)
html = read_html(html, headers)
document = Nokogiri::HTML(html)
Collection.new(document).parse
end
def read_html(html, headers={})
def read_html(html, headers=@http_headers)
open(html, headers) do |response|
@http_headers = response.meta if response.respond_to?(:meta)
@http_body = response.read