Module: IMW::Formats::Sgml
Overview
Defines methods to parse SGML-derived data formats (XML, HTML, &c.). This module isn’t directly used to extend resources. Instead, more specific modules (e.g. - IMW::Resources::Formats::Xml) are used.
Instance Method Summary collapse
-
#load {|Hpricot::Doc| ... } ⇒ Hpricot::Doc
Parse this resource using Hpricot and return (or yield if given a block) the resulting Hpricot::Doc.
-
#parse(parser) ⇒ Hash
Parse the Hpricot::Doc of this resource with the given
parser
.
Instance Method Details
#load {|Hpricot::Doc| ... } ⇒ Hpricot::Doc
Parse this resource using Hpricot and return (or yield if given a block) the resulting Hpricot::Doc.
15 16 17 18 19 20 21 22 23 |
# File 'lib/imw/formats/sgml.rb', line 15 def load &block require 'hpricot' sgml = Hpricot(io) if block_given? yield sgml else sgml end end |
#parse(parser) ⇒ Hash
Parse the Hpricot::Doc of this resource with the given parser
.
The parser can either be an IMW::Parsers::HtmlParser or a hash which will be used to build such a parser. See the documentation for IMW::Parsers::HtmlParser for more information.
35 36 37 38 39 40 41 |
# File 'lib/imw/formats/sgml.rb', line 35 def parse parser if parser.is_a?(IMW::Parsers::HtmlParser) parser.parse(load) else IMW::Parsers::HtmlParser.new(parser).parse(load) end end |