module MuchFactory::Random
Constants
- DICTIONARY
Public Class Methods
binary()
click to toggle source
# File lib/much-factory.rb, line 191 def self.binary [integer(10000)].pack("N*") end
date_string()
click to toggle source
# File lib/much-factory.rb, line 141 def self.date_string Time.now.strftime("%Y-%m-%d") end
datetime_string()
click to toggle source
# File lib/much-factory.rb, line 145 def self.datetime_string Time.now.strftime("%Y-%m-%d %H:%M:%S") end
dir_path_string(length = nil)
click to toggle source
# File lib/much-factory.rb, line 173 def self.dir_path_string(length = nil) length ||= 12 File.join(*string(length).scan(/.{1,4}/)) end
email_string(domain = nil, length = nil)
click to toggle source
# File lib/much-factory.rb, line 186 def self.email_string(domain = nil, length = nil) domain ||= "#{string(5)}.com" "#{string(length)}@#{domain}" end
file_name_string(length = nil)
click to toggle source
# File lib/much-factory.rb, line 168 def self.file_name_string(length = nil) length ||= 6 "#{string(length)}.#{string(3)}" end
file_path_string()
click to toggle source
# File lib/much-factory.rb, line 178 def self.file_path_string File.join(dir_path_string, file_name_string) end
float(max = nil)
click to toggle source
‘rand` with no args gives a float between 0 and 1
# File lib/much-factory.rb, line 137 def self.float(max = nil) (max || 100).to_f * rand end
hex_string(length = nil)
click to toggle source
# File lib/much-factory.rb, line 163 def self.hex_string(length = nil) length ||= 10 integer(("f" * length).hex - 1).to_s(16).rjust(length, "0") end
integer(max = nil)
click to toggle source
rand given a max int value returns integers between 0 and max-1
# File lib/much-factory.rb, line 132 def self.integer(max = nil) rand(max || 32_766) + 1 end
string(length = nil)
click to toggle source
# File lib/much-factory.rb, line 155 def self.string(length = nil) [*0..((length || 10) - 1)] .map{ |_n| DICTIONARY[rand(DICTIONARY.size)] } .join end
time_string()
click to toggle source
# File lib/much-factory.rb, line 149 def self.time_string Time.now.strftime("%H:%M:%S") end
url_string(host = nil, length = nil)
click to toggle source
# File lib/much-factory.rb, line 182 def self.url_string(host = nil, length = nil) File.join(host.to_s, dir_path_string(length)) end