Module: DataFactory::Random
- Included in:
- BaseAPI
- Defined in:
- lib/data_factory/random.rb
Constant Summary collapse
- CHARS =
['A'..'Z', 'a'..'z', '0'..'9'].map{|r|r.to_a}.flatten
Instance Method Summary collapse
-
#random_integer(max_size) ⇒ Object
Generates a random integer that is at most max_size.
-
#random_string_of_length(length) ⇒ Object
Generates a random string of letters and numbers of length.
-
#random_string_upto_length(max_length) ⇒ Object
Generates a random string of random length, which has a maximum length of max_length.
Instance Method Details
#random_integer(max_size) ⇒ Object
Generates a random integer that is at most max_size
23 24 25 |
# File 'lib/data_factory/random.rb', line 23 def random_integer(max_size) 1 + rand(max_size) end |
#random_string_of_length(length) ⇒ Object
Generates a random string of letters and numbers of length
7 8 9 10 11 12 13 |
# File 'lib/data_factory/random.rb', line 7 def random_string_of_length(length) str = '' 1.upto(length) do str << CHARS[rand(CHARS.size)] end str end |
#random_string_upto_length(max_length) ⇒ Object
Generates a random string of random length, which has a maximum length of max_length
17 18 19 20 |
# File 'lib/data_factory/random.rb', line 17 def random_string_upto_length(max_length) length = random_integer(max_length) random_string_of_length(length) end |