class NodeAction
Types of actions: 0 Push: [key:rule] 1 Pop: [key:POP] 2 function: [functionName(param0,param1)] (TODO!)
Attributes
node[RW]
ruleNode[RW]
target[RW]
type[RW]
Public Class Methods
new(node, raw)
click to toggle source
# File lib/tracery.rb, line 347 def initialize(node, raw) # puts("No node for NodeAction") if(node.nil?) # puts("No raw commands for NodeAction") if(raw.empty?) @node = node sections = raw.split(":") @target = sections.first if(sections.size == 1) then # No colon? A function! @type = 2 else # Colon? It's either a push or a pop @rule = sections[1] || "" if(@rule == "POP") @type = 1; else @type = 0; end end end
Public Instance Methods
activate()
click to toggle source
# File lib/tracery.rb, line 369 def activate grammar = @node.grammar case(@type) when 0 then # split into sections (the way to denote an array of rules) ruleSections = @rule.split(",") finishedRules = ruleSections.map{|ruleSection| n = TraceryNode.new(grammar, 0, { type: -1, raw: ruleSection }) n.expand() n.finishedText } # TODO: escape commas properly grammar.pushRules(@target, finishedRules, self) # puts("Push rules: #{@target} #{@ruleText}") when 1 then grammar.popRules(@target); when 2 then grammar.flatten(@target, true); end end
createUndo()
click to toggle source
# File lib/tracery.rb, line 394 def createUndo if(@type == 0) then return NodeAction.new(@node, "#{@target}:POP") end # TODO Not sure how to make Undo actions for functions or POPs return nil end
toText()
click to toggle source
# File lib/tracery.rb, line 402 def toText case(@type) when 0 then return "#{@target}:#{@rule}" when 1 then return "#{@target}:POP" when 2 then return "((some function))" else return "((Unknown Action))" end end