Class: REXML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_xmpp/patches/rexml.rb

Overview


Direct Known Subclasses

AgentXmpp::Xmpp::Element

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.import(xmlelement) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



55
56
57
# File 'lib/agent_xmpp/patches/rexml.rb', line 55

def self.import(xmlelement)
  self.new(xmlelement.name).import(xmlelement)
end

Instance Method Details

#delete_elements(element) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



60
61
62
# File 'lib/agent_xmpp/patches/rexml.rb', line 60

def delete_elements(element)
  elements.delete_all(element)
end

#first_element(e) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



20
21
22
# File 'lib/agent_xmpp/patches/rexml.rb', line 20

def first_element(e)
  elements.to_a(e).first
end

#first_element_text(e) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



25
26
27
28
# File 'lib/agent_xmpp/patches/rexml.rb', line 25

def first_element_text(e)
  el = first_element(e)
  el.nil? ? nil : el.text
end

#import(xmlelement) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/agent_xmpp/patches/rexml.rb', line 36

def import(xmlelement)
  if @name and @name != xmlelement.name
    raise "Trying to import an #{xmlelement.name} to a #{@name} !"
  end
  add_attributes(xmlelement.attributes.clone)
  @context = xmlelement.context
  xmlelement.each do |e|
    if e.kind_of? REXML::Element
      typed_add(e.deep_clone)
    elsif e.kind_of? REXML::Text
      add_text(e.value)
    else
      add(e.clone)
    end
  end
  self
end

#replace_element_text(e, t) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



9
10
11
12
13
14
15
16
17
# File 'lib/agent_xmpp/patches/rexml.rb', line 9

def replace_element_text(e, t)
  el = first_element(e)
  if el.nil?
    el = REXML::Element.new(e)
    add_element(el)
  end
  el.text = t if t
  self
end

#typed_add(e) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



31
32
33
# File 'lib/agent_xmpp/patches/rexml.rb', line 31

def typed_add(e)
  add(e)
end