Class: AgentX::XML

Inherits:
Object
  • Object
show all
Defined in:
lib/agentx/xml.rb

Instance Method Summary collapse

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

#attributesObject



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

#childrenObject



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

#inspectObject



55
56
57
# File 'lib/agentx/xml.rb', line 55

def inspect
  to_xml
end

#nextObject



33
34
35
# File 'lib/agentx/xml.rb', line 33

def next
  XML.new(@xml.next)
end

#parentObject



25
26
27
# File 'lib/agentx/xml.rb', line 25

def parent
  XML.new(@xml.parent)
end

#previousObject



37
38
39
# File 'lib/agentx/xml.rb', line 37

def previous
  XML.new(@xml.previous)
end

#to_nokogiriObject



59
60
61
# File 'lib/agentx/xml.rb', line 59

def to_nokogiri
  @xml
end

#to_sObject



51
52
53
# File 'lib/agentx/xml.rb', line 51

def to_s
  to_xml
end

#to_xmlObject



13
14
15
# File 'lib/agentx/xml.rb', line 13

def to_xml
  @xml.to_xml
end