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
-
.read(s, opt = nil) ⇒ Object
The entry point : takes a radial string and returns, if possible, a ruote tree.
-
.understands?(s) ⇒ Boolean
Returns tree if s seems to contain a radial process definition.
Class Method Details
.read(s, opt = nil) ⇒ Object
The entry point : takes a radial string and returns, if possible, a ruote tree.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/ruote/reader/radial.rb', line 269 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 end |
.understands?(s) ⇒ Boolean
Returns tree if s seems to contain a radial process definition
259 260 261 262 263 264 |
# File 'lib/ruote/reader/radial.rb', line 259 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 |