Class: Mapricot::AbstractDoc
- Inherits:
-
Object
- Object
- Mapricot::AbstractDoc
- Defined in:
- lib/mapricot/abstract_doc.rb
Overview
AbstractDoc should be able to find tags, get inner tag content. Find all tags (return an array) I think I will also need AbstractNode
Instance Method Summary collapse
- #find(tagname) ⇒ Object
-
#initialize(string) ⇒ AbstractDoc
constructor
A new instance of AbstractDoc.
Constructor Details
#initialize(string) ⇒ AbstractDoc
Returns a new instance of AbstractDoc.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mapricot/abstract_doc.rb', line 15 def initialize(string) if Mapricot.parser == :libxml string = string.read if string.is_a?(StringIO) @udoc = LibXML::XML::Parser.string(string).parse elsif Mapricot.parser == :hpricot @udoc = Hpricot::XML(string) elsif Mapricot.parser == :nokogiri @udoc = Nokogiri::XML(string) end end |
Instance Method Details
#find(tagname) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mapricot/abstract_doc.rb', line 27 def find(tagname) if Mapricot.parser == :libxml AbstractNodeList.new(@udoc.find("//#{tagname}")) # hmm... elsif Mapricot.parser == :hpricot # AbstractNodeList.new(@udoc/tagname) AbstractNodeList.new(@udoc/"//#{tagname}") elsif Mapricot.parser == :nokogiri AbstractNodeList.new(@udoc.search(tagname)) # AbstractNodeList.new(@udoc.xpath("//#{tagname}")) end end |