Class: Xmlish::Walker

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

Instance Method Summary collapse

Constructor Details

#initialize(nodes, callbacks) ⇒ Walker

Returns a new instance of Walker.

Parameters:

  • nodes (Array<Node>)
  • callbacks (Array<#call>)


157
158
159
160
# File 'lib/xmlish.rb', line 157

def initialize nodes, callbacks
  @nodes = nodes
  @callbacks = callbacks
end

Instance Method Details

#walk(nodes = @nodes) ⇒ String

Returns:

  • (String)


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/xmlish.rb', line 163

def walk nodes=@nodes
  nodes.collect do |node|
    if Node === node
      callback = callback_for_tag node.attr_name
      if callback
        callback.call(Proc.new{walk node.nodes})
      else
        walk node.nodes
      end
    else
      callback = callback_for_tag 'text'
      if callback
        callback.call(Proc.new{node})
      else
        node
      end
    end
  end.join('')
end