Class: AgentX::XML
- Inherits:
-
Object
- Object
- AgentX::XML
- Defined in:
- lib/agentx/xml.rb
Instance Method Summary collapse
- #[](attr) ⇒ Object
- #all(selector) ⇒ Object
- #attributes ⇒ Object
- #children ⇒ Object
- #first(selector) ⇒ Object
-
#initialize(xml) ⇒ XML
constructor
A new instance of XML.
- #inspect ⇒ Object
- #next ⇒ Object
- #parent ⇒ Object
- #previous ⇒ Object
- #to_nokogiri ⇒ Object
- #to_s ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(xml) ⇒ XML
Returns a new instance of XML.
5 6 7 8 9 10 11 |
# File 'lib/agentx/xml.rb', line 5 def initialize(xml) if xml.kind_of?(String) @xml = Nokogiri::XML(xml) else @xml = xml end end |
Instance Method Details
#[](attr) ⇒ Object
47 48 49 |
# File 'lib/agentx/xml.rb', line 47 def [](attr) @xml[attr.to_s] end |
#all(selector) ⇒ Object
21 22 23 |
# File 'lib/agentx/xml.rb', line 21 def all(selector) @xml.css(selector).map { |e| XML.new(e) } end |
#attributes ⇒ Object
41 42 43 44 45 |
# File 'lib/agentx/xml.rb', line 41 def attributes h = {} @xml.attribute_nodes.each { |n| h[n.name] = n.value } h end |
#children ⇒ Object
29 30 31 |
# File 'lib/agentx/xml.rb', line 29 def children @xml.children.map { |e| XML.new(e) } end |
#first(selector) ⇒ Object
17 18 19 |
# File 'lib/agentx/xml.rb', line 17 def first(selector) (e = @xml.css(selector).first) && XML.new(e) end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/agentx/xml.rb', line 55 def inspect to_xml end |
#previous ⇒ Object
37 38 39 |
# File 'lib/agentx/xml.rb', line 37 def previous XML.new(@xml.previous) end |
#to_nokogiri ⇒ Object
59 60 61 |
# File 'lib/agentx/xml.rb', line 59 def to_nokogiri @xml end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/agentx/xml.rb', line 51 def to_s to_xml end |
#to_xml ⇒ Object
13 14 15 |
# File 'lib/agentx/xml.rb', line 13 def to_xml @xml.to_xml end |