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.
467 468 469 470 471 472 473 474 475 |
# File 'lib/tracery.rb', line 467 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.
465 466 467 |
# File 'lib/tracery.rb', line 465 def isDynamic @isDynamic end |
Instance Method Details
#clearState ⇒ Object
477 478 479 480 481 482 |
# File 'lib/tracery.rb', line 477 def clearState # Clear the stack and clear all ruleset usages @stack = [@baseRules] @uses = [] @baseRules.clearState end |
#getActiveRules ⇒ Object
502 503 504 505 |
# File 'lib/tracery.rb', line 502 def getActiveRules return nil if @stack.empty? return @stack.last.selectRule end |
#popRules ⇒ Object
489 490 491 |
# File 'lib/tracery.rb', line 489 def popRules @stack.pop end |
#pushRules(rawRules) ⇒ Object
484 485 486 487 |
# File 'lib/tracery.rb', line 484 def pushRules(rawRules) rules = RuleSet.new(@grammar, rawRules) @stack.push rules end |
#rulesToJSON ⇒ Object
507 508 509 |
# File 'lib/tracery.rb', line 507 def rulesToJSON return @rawRules.to_json end |
#selectRule(node, errors) ⇒ Object
493 494 495 496 497 498 499 500 |
# File 'lib/tracery.rb', line 493 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 |