Module: CanParse
- Included in:
- FMyLife::Account, XMLStruct, XMLStruct
- Defined in:
- lib/fmylife/xmlstruct.rb
Overview
Methods for parser-agnostic parsing
Instance Method Summary collapse
- #xml_attribute(element, attribute) ⇒ Object
- #xml_content(element) ⇒ Object
-
#xml_doc(body) ⇒ Object
Helper method that encapsulates a string into an XML document.
- #xpath(element, path) ⇒ Object
Instance Method Details
#xml_attribute(element, attribute) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fmylife/xmlstruct.rb', line 44 def xml_attribute(element,attribute) case FMyLife.parser when :nokogiri element[attribute] when :hpricot element.get_attribute(attribute) when :rexml element.attributes[attribute] when :nokogiri element.attributes[attribute] end end |
#xml_content(element) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fmylife/xmlstruct.rb', line 31 def xml_content(element) case FMyLife.parser when :nokogiri element.content when :hpricot element.inner_text when :rexml element.text when :libxml element.content end end |
#xml_doc(body) ⇒ Object
Helper method that encapsulates a string into an XML document
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fmylife/xmlstruct.rb', line 4 def xml_doc(body) case FMyLife.parser when :nokogiri Nokogiri::XML(body) when :hpricot Hpricot(body) when :rexml REXML::Document.new(body) when :libxml LibXML::XML::Parser.string(body).parse end end |
#xpath(element, path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fmylife/xmlstruct.rb', line 17 def xpath(element,path) case FMyLife.parser when :nokogiri element.xpath(path) when :hpricot puts "in hpricot" element/path #force the // when :rexml REXML::XPath.match(element,path) when :libxml element.find(path) end end |