Module: MPatch::Random

Defined in:
lib/mpatch/random.rb

Instance Method Summary collapse

Instance Method Details

#boolean ⇒ Object



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

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

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



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

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

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



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

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

#integer(length = 3) ⇒ Object



14
15
16
# File 'lib/mpatch/random.rb', line 14

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

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



4
5
6
7
8
9
10
11
12
# File 'lib/mpatch/random.rb', line 4

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



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

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