Class: Forgery::Date
Constant Summary
collapse
- DAYS =
Forgery::Extend(%w{Sunday Monday Tuesday Wednesday Thursday Friday Saturday})
- DAYS_ABBR =
Forgery::Extend(%w{Sun Mon Tue Wed Thu Fri Sat})
- MONTHS =
Forgery::Extend(%w{January February March April May June July August September October November December})
- MONTHS_ABBR =
Forgery::Extend(%w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))
Constants inherited
from Forgery
VERSION
Class Method Summary
collapse
Methods inherited from Forgery
Extend, dictionaries, formats, load_from!, load_paths, rails?, rails_root
Class Method Details
.date(options = {}) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/forgery/forgery/date.rb', line 45
def self.date(options={})
options = {:future => false, :past => false, :min_delta => 0, :max_delta => 7300}.merge(options)
::Date.today + delta(options)
end
|
.day ⇒ Object
41
42
43
|
# File 'lib/forgery/forgery/date.rb', line 41
def self.day
1 + rand(31)
end
|
.day_of_week(options = {}) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/forgery/forgery/date.rb', line 9
def self.day_of_week(options={})
options = {:abbr => false}.merge(options)
if (options[:abbr])
DAYS_ABBR.random.unextend
else
DAYS.random.unextend
end
end
|
.month(options = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/forgery/forgery/date.rb', line 19
def self.month(options={})
options = {:abbr => false, :numerical => false}.merge(options)
if (options[:numerical])
1 + rand(12)
else
if (options[:abbr])
MONTHS_ABBR.random.unextend
else
MONTHS.random.unextend
end
end
end
|
.year(options = {}) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/forgery/forgery/date.rb', line 34
def self.year(options={})
options = {:future => false, :past => false, :min_delta => 0, :max_delta => 20}.merge(options)
DateTime.now.year + delta(options)
end
|