2

How is possible to define a minimum and maximum length of user login generated by

FFaker::InternetSE.login_user_name

Used gem FFaker

Jan Krupa
  • 484
  • 9
  • 21

1 Answers1

2

You can store the result of FFaker::InternetSE.login_user_name and check if the size of the string generated is between the minimum and maximum length you need, if so, return it, otherwise call the function again:

require 'ffaker'

def login_user_name(min, max)
  raise 'max can not be minor than min' if min > max
  username = FFaker::InternetSE.login_user_name
  username.size.between?(min, max) ? username : login_user_name(min, max)
end

p login_user_name(8, 9) # christian
p login_user_name(9, 8) # `login_user_name': max can not be minor than min (RuntimeError)
Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59