adds Microformats::Parser to move module methods into class instance
This commit is contained in:
parent
101f4871ad
commit
22d84e0845
2 changed files with 19 additions and 7 deletions
|
@ -4,6 +4,7 @@ require "json"
|
||||||
require "active_support/inflector"
|
require "active_support/inflector"
|
||||||
|
|
||||||
require "microformats2/version"
|
require "microformats2/version"
|
||||||
|
require "microformats2/parser"
|
||||||
require "microformats2/format_parser"
|
require "microformats2/format_parser"
|
||||||
require "microformats2/property_parser"
|
require "microformats2/property_parser"
|
||||||
require "microformats2/collection"
|
require "microformats2/collection"
|
||||||
|
@ -22,17 +23,13 @@ require "microformats2/implied_property/url"
|
||||||
module Microformats2
|
module Microformats2
|
||||||
class << self
|
class << self
|
||||||
def parse(html)
|
def parse(html)
|
||||||
html = read_html(html)
|
Parser.new.parse(html)
|
||||||
document = Nokogiri::HTML(html)
|
|
||||||
Collection.new(document).parse
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_html(html)
|
def read_html(html)
|
||||||
open(html).read
|
Parser.new.read_html(html)
|
||||||
rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
|
|
||||||
html
|
|
||||||
end
|
end
|
||||||
end # class << self
|
end # class << self
|
||||||
|
|
||||||
class InvalidPropertyPrefix < StandardError; end
|
class InvalidPropertyPrefix < StandardError; end
|
||||||
end
|
end
|
||||||
|
|
15
lib/microformats2/parser.rb
Normal file
15
lib/microformats2/parser.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue