sets Microformats2::Parser#http_headers on initialize
This commit is contained in:
parent
ed2f66002e
commit
78df1dc8bc
1 changed files with 6 additions and 2 deletions
|
@ -2,13 +2,17 @@ module Microformats2
|
||||||
class Parser
|
class Parser
|
||||||
attr_reader :http_headers, :http_body
|
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)
|
html = read_html(html, headers)
|
||||||
document = Nokogiri::HTML(html)
|
document = Nokogiri::HTML(html)
|
||||||
Collection.new(document).parse
|
Collection.new(document).parse
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_html(html, headers={})
|
def read_html(html, headers=@http_headers)
|
||||||
open(html, headers) do |response|
|
open(html, headers) do |response|
|
||||||
@http_headers = response.meta if response.respond_to?(:meta)
|
@http_headers = response.meta if response.respond_to?(:meta)
|
||||||
@http_body = response.read
|
@http_body = response.read
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue