Module: OpenWFE::ExpressionTree

Defined in:
lib/openwfe/expool/parser.rb

Overview

A set of methods for manipulating / querying a process expression tree

Class Method Summary collapse

Class Method Details

.get_description(tree) ⇒ Object

Extracts the description out of a process definition tree.

TODO #14964 : add language support here



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/openwfe/expool/parser.rb', line 152

def self.get_description (tree)

    return tree.last.first.to_s if tree.first == 'description'

    tree.last.each do |child|
        d = get_description(child)
        return d if d
    end

    nil
end

.to_code_s(tree, indentation = 0) ⇒ Object

Returns a string containing the ruby code that generated this raw representation tree.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/openwfe/expool/parser.rb', line 168

def self.to_code_s (tree, indentation = 0)

    s = ""
    tab = "    "
    ind = tab * indentation

    s << ind
    s << OpenWFE::make_safe(tree.first)

    sa = ""
    tree[1].each do |k, v|
        sa << ", :#{OpenWFE::to_underscore(k)} => '#{v}'"
    end
    s << sa[1..-1] if sa.length > 0

    if tree.last.length > 0
        s << " do\n"
        tree.last.each do |child|
            #if child.respond_to?(:to_code_s)
            if child.is_a?(Array) and child.size == 3 # and ...
                s << to_code_s(child, indentation + 1)
            else
                s << ind
                s << tab
                s << "'#{child.to_s}'"
            end
            s << "\n"
        end
        s << ind
        s << "end"
    end

    s
end

.to_s(tree) ⇒ Object



227
228
229
230
# File 'lib/openwfe/expool/parser.rb', line 227

def self.to_s (tree)

    to_xml(tree).to_s
end

.to_xml(tree) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/openwfe/expool/parser.rb', line 203

def self.to_xml (tree)

    elt = REXML::Element.new tree.first

    tree[1].each do |k, v|

        elt.attributes[k] = v
    end

    tree.last.each do |child|

        #if child.kind_of?(SimpleExpRepresentation)
        if child.is_a?(Array) and child.size == 3

            elt << to_xml(child)
        else

            elt << REXML::Text.new(child.to_s)
        end
    end

    elt
end