Class: Xmlish::Reconstructor

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

Instance Method Summary collapse

Constructor Details

#initialize(nodes, callbacks) ⇒ Reconstructor

Returns a new instance of Reconstructor.

Parameters:

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


112
113
114
115
# File 'lib/xmlish.rb', line 112

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

Instance Method Details

#reconstruct(nodes = @nodes) ⇒ String

Returns:

  • (String)


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/xmlish.rb', line 118

def reconstruct nodes=@nodes
  nodes.collect do |node|
    if Node === node
      callback = callback_for_tag node.attr_name
      if callback
        callback.call(reconstruct node.nodes)
      else
        reconstruct node.nodes
      end
    else
      callback = callback_for_tag 'text'
      if callback
        callback.call(node)
      else
        node
      end
    end
  end.join('')
end