adds Microformats::Parser to move module methods into class instance

This commit is contained in:
Jessica Dillon & Jessica Lynn Suttles 2013-07-01 16:31:39 -07:00
parent 101f4871ad
commit 22d84e0845
2 changed files with 19 additions and 7 deletions

View file

@ -4,6 +4,7 @@ require "json"
require "active_support/inflector"
require "microformats2/version"
require "microformats2/parser"
require "microformats2/format_parser"
require "microformats2/property_parser"
require "microformats2/collection"
@ -22,17 +23,13 @@ require "microformats2/implied_property/url"
module Microformats2
class << self
def parse(html)
html = read_html(html)
document = Nokogiri::HTML(html)
Collection.new(document).parse
Parser.new.parse(html)
end
def read_html(html)
open(html).read
rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
html
Parser.new.read_html(html)
end
end # class << self
class InvalidPropertyPrefix < StandardError; end
end
end

View file

@ -0,0 +1,15 @@
module Microformats2
class Parser
def parse(html)
html = read_html(html)
document = Nokogiri::HTML(html)
Collection.new(document).parse
end
def read_html(html)
open(html).read
rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
html
end
end
end