diff --git a/lib/microformats2.rb b/lib/microformats2.rb index bbf8533..03e1ac8 100644 --- a/lib/microformats2.rb +++ b/lib/microformats2.rb @@ -1,5 +1,16 @@ +require "nokogiri" +require "open-uri" require "microformats2/version" module Microformats2 - # Your code goes here... + def self.parse(html) + html = read_html(html) + Nokogiri::HTML(html) + end + + def self.read_html(html) + open(html).read + rescue Errno::ENOENT => e + html + end end diff --git a/spec/lib/microformats2_spec.rb b/spec/lib/microformats2_spec.rb new file mode 100644 index 0000000..8e54335 --- /dev/null +++ b/spec/lib/microformats2_spec.rb @@ -0,0 +1,23 @@ +require "spec_helper" +require "microformats2" + +describe Microformats2 do + describe "::read_html" do + before do + @html = <<-HTML.strip +

Jessica Lynn Suttles

+ HTML + end + it "can be a string of html" do + Microformats2.read_html(@html).should include @html + end + it "can be a file path to html" do + html = "spec/support/simple.html" + Microformats2.read_html(html).should include @html + end + it "can be a url to html" do + html = "http://google.com" + Microformats2.read_html(html).should include "google" + end + end +end diff --git a/spec/support/simple.html b/spec/support/simple.html new file mode 100644 index 0000000..307441c --- /dev/null +++ b/spec/support/simple.html @@ -0,0 +1,6 @@ + + + +

Jessica Lynn Suttles

+ +