module FFaker::String
def process_token(tokens)
def process_token(tokens) return '' if tokens.empty? token = tokens.shift case token when '?' then # TODO: Let ? generate nothing '' # We already printed its target when '+' then tokens.unshift(token) if rand(0..1) == 1 # Leave the `+` on to run again process_token(@last_token) # Run the last one at least once when '*' then tokens.unshift(token) if rand(0..1) == 1 # Leave the `*` on to run again return '' if rand(0..1) == 1 # Or maybe do nothing process_token(@last_token) # Else run the last one again when '{' then number = +'' while (ch = tokens.shift) != '}' number << ch end number = number.to_i - 1 t = @last_token.dup Array.new(number) { process_token(t.dup) }.join else generate_token token, tokens end end