diff --git a/lib/microformats2.rb b/lib/microformats2.rb index e5a9257..8515004 100644 --- a/lib/microformats2.rb +++ b/lib/microformats2.rb @@ -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 \ No newline at end of file +end diff --git a/lib/microformats2/parser.rb b/lib/microformats2/parser.rb new file mode 100644 index 0000000..680a034 --- /dev/null +++ b/lib/microformats2/parser.rb @@ -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