16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/genny/string.rb', line 16
def self.genny(opts = {})
opts = Genny.symbolize(opts)
viable_formats = @@formats.keys & [*opts[:format]]
return @@formats[viable_formats.sample].call(opts) unless viable_formats.empty?
if (re = ::Regexp.new(opts[:format]) rescue false)
begin
return re.extend(Genny::Regexp).genny
rescue
end
end
guess = @@hints.inject(nil) { |guess, hint|
break guess if !(guess = hint.call(opts)).nil?
} if opts[:hint]
return guess unless guess.nil?
opts[:minLength] ||= 10
opts[:maxLength] ||= 10
length = Random.rand(opts[:maxLength] - opts[:minLength] + 1) + opts[:minLength]
('a'..'z').to_a.sample(length).join
end
|