Module: Ruote::RadialReader

Defined in:
lib/ruote/reader/radial.rb

Overview

Turning radial strings into ruote trees.

Defined Under Namespace

Classes: Node, Parser, PreRoot, Transformer

Class Method Summary collapse

Class Method Details

.read(s, opt = nil) ⇒ Object

The entry point : takes a radial string and returns, if possible, a ruote tree.



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/ruote/reader/radial.rb', line 251

def self.read(s, opt=nil)

  parser = Parser.new
  transformer = Transformer.new

  lines = parser.parse("\n#{s}\n")
  nodes = transformer.apply(lines)

  root = PreRoot.new("#{s.strip.split("\n").first}...")
  current = root

  nodes = [] unless nodes.is_a?(Array)
    # force ArgumentError via empty PreRoot

  nodes.each do |node|

    parent = current

    if node.indentation == current.indentation
      parent = current.parent
    elsif node.indentation < current.indentation
      while node.indentation <= parent.indentation
        parent = parent.parent
      end
    end

    node.parent = parent
    current = node
  end

  root.to_a

rescue Parslet::ParseFailed => e
  class << e; attr_accessor :error_tree; end
  e.error_tree = parser.root.error_tree
  raise e
end

.understands?(s) ⇒ Boolean

Returns tree if s seems to contain a radial process definition

Returns:

  • (Boolean)


241
242
243
244
245
246
# File 'lib/ruote/reader/radial.rb', line 241

def self.understands?(s)

  return false if s.match(/\n *end\b/)
  return false if s.match(/\bRuote\.(process_definition|workflow_definition|define)\b/)
  true
end