Class: TeXML::Node

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

Overview

Common node superclass (also node factory, see Node#create)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.



60
61
62
# File 'lib/texml.rb', line 60

def initialize(node)
  @node = node
end

Class Method Details

.create(node) ⇒ Object

Creates a node handler object appropriate for the specified XML node, based on the name of the node (uses information from NODE_HANDLERS).



49
50
51
52
53
54
55
56
57
58
# File 'lib/texml.rb', line 49

def Node.create(node)
  kind = node.name
  kind = '#text' if kind == 'text'
  handlerClass = NODE_HANDLERS[kind]
  if !handlerClass.nil?
	handlerClass.new(node)
  else
	nil
  end
end

Instance Method Details

#childrenValue(*childTypes) ⇒ Object

Aggregates the values of all the children of this Node whose node name is included in the parameters, in the document order of the children.



67
68
69
70
71
72
73
74
75
76
# File 'lib/texml.rb', line 67

def childrenValue(*childTypes)
  tex = ''
  @node.children.each do |kid|
	if childTypes.include?(kid.name) || (kid.text? && childTypes.include?('#text'))
	  node = Node.create(kid)
	  tex << node.to_tex unless node.nil?
	end
  end
  return tex
end