Class: Microformats2::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/microformats2/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



5
6
7
# File 'lib/microformats2/parser.rb', line 5

def initialize
  @http_headers = {}
end

Instance Attribute Details

#http_bodyObject (readonly)

Returns the value of attribute http_body.



3
4
5
# File 'lib/microformats2/parser.rb', line 3

def http_body
  @http_body
end

#http_headersObject (readonly)

Returns the value of attribute http_headers.



3
4
5
# File 'lib/microformats2/parser.rb', line 3

def http_headers
  @http_headers
end

Instance Method Details

#parse(html, headers = {}) ⇒ Object



9
10
11
12
13
# File 'lib/microformats2/parser.rb', line 9

def parse(html, headers={})
  html = read_html(html, headers)
  document = Nokogiri::HTML(html)
  Collection.new(document).parse
end

#read_html(html, headers = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/microformats2/parser.rb', line 15

def read_html(html, 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