Class: LibXML::XML::Node

Inherits:
Object
  • Object
show all
Includes:
Traverseable
Defined in:
lib/axml/libxml.rb

Instance Method Summary collapse

Instance Method Details

#childObject



65
66
67
68
69
70
71
72
73
# File 'lib/axml/libxml.rb', line 65

def child
  kid = self.old_child
  return nil if kid.nil?
  while kid.old_text?
    kid = kid.old_child
    return nil if kid.nil?
  end
  kid
end

#find_children(name) ⇒ Object



78
79
80
# File 'lib/axml/libxml.rb', line 78

def find_children(name)
  find("child::#{name}")
end

#find_first_child(name) ⇒ Object



75
76
77
# File 'lib/axml/libxml.rb', line 75

def find_first_child(name)
  find_first("child::#{name}")
end

#find_first_descendant(name) ⇒ Object



81
82
83
# File 'lib/axml/libxml.rb', line 81

def find_first_descendant(name)
  find_first("descendant::#{name}")
end

#old_childObject



40
# File 'lib/axml/libxml.rb', line 40

alias_method :old_child, :child

#old_text?Object



41
# File 'lib/axml/libxml.rb', line 41

alias_method :old_text?, :text?

#textObject Also known as: content



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/axml/libxml.rb', line 48

def text
  cont = self.old_content
  if cont == ""
    nil
  else
    cont
  end

  #kid = self.old_child
  #return nil unless kid
  ##p(kid.methods - Object.methods)
  #if kid.old_text?
  #  kid.to_s
  #end
end

#text?Boolean



44
45
46
# File 'lib/axml/libxml.rb', line 44

def text?
  self.old_child.old_text?
end

#traverse(type = :pre, &block) ⇒ Object

full traversal from the initial node



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/axml/libxml.rb', line 86

def traverse(type=:pre, &block)
  if type == :pre
    block.call(self) unless self.old_text?
  end
  children.each do |child|
    child.traverse(type, &block)
  end
  if type == :post
    block.call(self) unless self.old_text?
  end
end