Method: Expgen::Randomizer#randomize

Defined in:
lib/expgen/randomizer.rb

#randomize(tree) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/expgen/randomizer.rb', line 25

def randomize(tree)
  case tree
    when Array              then tree.map { |el| randomize(el) }.join
    when Nodes::Alternation then randomize(tree.options.sample)
    when Nodes::Group       then repeat(tree.repeat, tree.max) { randomize(tree.elements) }
    when Nodes::Character   then repeat(tree.repeat, tree.max) { tree.chars.sample }
  end
end