Class: Succubus::Generator
- Inherits:
-
Object
- Object
- Succubus::Generator
- Defined in:
- lib/succubus/generator.rb
Overview
Class Method Summary collapse
-
.run(grammar, rule, seed = nil) ⇒ Object
Run through a given Grammar, starting at a given rule.
Instance Method Summary collapse
Constructor Details
#initialize(grammar, seed = nil) ⇒ Generator
Create a new Succubus::Generator, ready to run through the supplied Succubus::Grammar, optionally with the given random seed.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/succubus/generator.rb', line 25 def initialize(grammar, seed=nil) @rules = grammar.rules @seed = seed unless @seed srand() @seed = rand(0xffffffff) end srand(@seed) @errors = [] end |
Class Method Details
.run(grammar, rule, seed = nil) ⇒ Object
Run through a given Succubus::Grammar, starting at a given rule. Optionally use a given random seed.
15 16 17 |
# File 'lib/succubus/generator.rb', line 15 def self.run(grammar, rule, seed=nil) new(grammar, seed).run(rule) end |
Instance Method Details
#run(rule) ⇒ Result
Produce a random Result string from the Generator’s Succubus::Grammar
42 43 44 45 46 47 |
# File 'lib/succubus/generator.rb', line 42 def run(rule) @result = Result.new(@seed, invoke(rule)) @result.set_errors(@errors) return @result end |