Class: TracerySymbol
- Inherits:
-
Object
- Object
- TracerySymbol
- Defined in:
- lib/tracery.rb
Instance Attribute Summary collapse
-
#isDynamic ⇒ Object
Returns the value of attribute isDynamic.
Instance Method Summary collapse
- #clearState ⇒ Object
- #getActiveRules ⇒ Object
-
#initialize(grammar, key, rawRules) ⇒ TracerySymbol
constructor
A new instance of TracerySymbol.
- #popRules ⇒ Object
- #pushRules(rawRules) ⇒ Object
- #rulesToJSON ⇒ Object
- #selectRule(node, errors) ⇒ Object
Constructor Details
#initialize(grammar, key, rawRules) ⇒ TracerySymbol
Returns a new instance of TracerySymbol.
481 482 483 484 485 486 487 488 489 |
# File 'lib/tracery.rb', line 481 def initialize(grammar, key, rawRules) # Symbols can be made with a single value, and array, or array of objects of (conditions/values) @key = key @grammar = grammar @rawRules = rawRules @baseRules = RuleSet.new(@grammar, @rawRules) clearState end |
Instance Attribute Details
#isDynamic ⇒ Object
Returns the value of attribute isDynamic.
479 480 481 |
# File 'lib/tracery.rb', line 479 def isDynamic @isDynamic end |
Instance Method Details
#clearState ⇒ Object
491 492 493 494 495 496 |
# File 'lib/tracery.rb', line 491 def clearState # Clear the stack and clear all ruleset usages @stack = [@baseRules] @uses = [] @baseRules.clearState end |
#getActiveRules ⇒ Object
516 517 518 519 |
# File 'lib/tracery.rb', line 516 def getActiveRules return nil if @stack.empty? return @stack.last.selectRule end |
#popRules ⇒ Object
503 504 505 |
# File 'lib/tracery.rb', line 503 def popRules @stack.pop end |
#pushRules(rawRules) ⇒ Object
498 499 500 501 |
# File 'lib/tracery.rb', line 498 def pushRules(rawRules) rules = RuleSet.new(@grammar, rawRules) @stack.push rules end |
#rulesToJSON ⇒ Object
521 522 523 |
# File 'lib/tracery.rb', line 521 def rulesToJSON return @rawRules.to_json end |
#selectRule(node, errors) ⇒ Object
507 508 509 510 511 512 513 514 |
# File 'lib/tracery.rb', line 507 def selectRule(node, errors) @uses.push({ node: node }) if(@stack.empty?) then errors << "The rule stack for '#{@key}' is empty, too many pops?" return "((#{@key}))" end return @stack.last.selectRule end |