Class: Microformats2::Parser
- Inherits:
-
Object
- Object
- Microformats2::Parser
- Defined in:
- lib/microformats2/parser.rb
Instance Attribute Summary collapse
-
#http_body ⇒ Object
readonly
Returns the value of attribute http_body.
-
#http_headers ⇒ Object
readonly
Returns the value of attribute http_headers.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(html, headers = {}) ⇒ Object
- #read_html(html, headers = {}) ⇒ Object
Constructor Details
#initialize ⇒ Parser
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_body ⇒ Object (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_headers ⇒ Object (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. if response.respond_to?(:meta) @http_body = response.read end @http_body rescue Errno::ENOENT, Errno::ENAMETOOLONG => e @http_body = html end |