microformats2/lib/microformats2/parser.rb
Jessica Dillon & Jessica Lynn Suttles 3f61f48025 adds parser specs
2013-07-01 17:34:15 -07:00

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