25 lines
608 B
Ruby
25 lines
608 B
Ruby
module Microformats2
|
|
class Parser
|
|
attr_reader :http_headers, :http_body
|
|
|
|
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=@http_headers)
|
|
open(html, headers) do |response|
|
|
@http_headers = response.meta if response.respond_to?(:meta)
|
|
@http_body = response.read
|
|
end
|
|
@http_body
|
|
rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
|
|
@http_body = html
|
|
end
|
|
end
|
|
end
|