Module: MPatch::Extend::Random

Defined in:
lib/mpatch/random.rb

Instance Method Summary collapse

Instance Method Details

#booleanObject



21
22
23
# File 'lib/mpatch/random.rb', line 21

def boolean
  self.rand(2) == 1
end

#date(from = Time.at(1114924812), to = Time.now) ⇒ Object



29
30
31
# File 'lib/mpatch/random.rb', line 29

def date from = Time.at(1114924812), to = Time.now
  self.rand(from..to).to_date
end

#datetime(from = Time.at(1114924812), to = Time.now) ⇒ Object



33
34
35
# File 'lib/mpatch/random.rb', line 33

def datetime from = Time.at(1114924812), to = Time.now
  self.rand(from..to).to_datetime
end

#integer(length = 3) ⇒ Object



17
18
19
# File 'lib/mpatch/random.rb', line 17

def integer(length= 3)
  self.rand(length)
end

#string(length = 7, amount = 1, hyphen = " ") ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/mpatch/random.rb', line 7

def string(length= 7,amount=1,hyphen= " ")
  amount_container= []
  amount.times do
    mrg= ""
    mrg= (0...length).map{ ('a'..'z').to_a[rand(26)] }.join
    amount_container.push mrg
  end
  return amount_container.join(hyphen)
end

#time(from = Time.at(1114924812), to = Time.now) ⇒ Object



25
26
27
# File 'lib/mpatch/random.rb', line 25

def time from = Time.at(1114924812), to = Time.now
  self.rand(from..to)
end