Class: Code::Object::Date
Constant Summary
Constants inherited
from Code::Object
NUMBER_CLASSES
Instance Attribute Summary
Attributes inherited from Code::Object
#raw
Class Method Summary
collapse
Instance Method Summary
collapse
#<=>, #==, #as_json, as_json, #code_and_operator, code_and_operator, code_as_json, #code_as_json, code_different, #code_different, code_equal_equal, #code_equal_equal, code_equal_equal_equal, #code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, code_inclusive_range, #code_inclusive_range, code_new, code_or_operator, #code_or_operator, code_self, #code_self, code_to_json, #code_to_json, falsy?, #falsy?, #hash, inspect, maybe, multi_fetch, #multi_fetch, #nothing?, nothing?, repeat, sig, #sig, #succ, #to_code, to_json, #to_json, to_s, truthy?, #truthy?, |
Constructor Details
#initialize(*args, **_kargs) ⇒ Date
Returns a new instance of Date.
6
7
8
9
10
|
# File 'lib/code/object/date.rb', line 6
def initialize(*args, **_kargs, &)
@raw = ::Date.parse(args.map(&:to_s).join("-"))
rescue ::Date::Error
@raw = ::Date.current
end
|
Class Method Details
.call(**args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/code/object/date.rb', line 12
def self.call(**args)
code_operator = args.fetch(:operator, nil).to_code
case code_operator.to_s
when "tomorrow"
sig(args)
code_tomorrow
when "yesterday"
sig(args)
code_yesterday
when "today"
sig(args)
code_today
when "now"
sig(args)
code_now
when "hour"
sig(args)
code_hour
else
super
end
end
|
.code_hour ⇒ Object
36
37
38
|
# File 'lib/code/object/date.rb', line 36
def self.code_hour
code_today.code_hour
end
|
40
41
42
43
|
# File 'lib/code/object/date.rb', line 40
def self.code_now
::Time.zone ||= Time::DEFAULT_ZONE
new(::Time.zone.now.beginning_of_day)
end
|
.code_today ⇒ Object
45
46
47
48
|
# File 'lib/code/object/date.rb', line 45
def self.code_today
::Time.zone ||= Time::DEFAULT_ZONE
new(::Time.zone.now.beginning_of_day)
end
|
.code_tomorrow ⇒ Object
50
51
52
53
|
# File 'lib/code/object/date.rb', line 50
def self.code_tomorrow
::Time.zone ||= Time::DEFAULT_ZONE
new(::Time.zone.tomorrow.beginning_of_day)
end
|
.code_yesterday ⇒ Object
55
56
57
58
|
# File 'lib/code/object/date.rb', line 55
def self.code_yesterday
::Time.zone ||= Time::DEFAULT_ZONE
new(::Time.zone.yesterday.beginning_of_day)
end
|
Instance Method Details
#call(**args) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/code/object/date.rb', line 60
def call(**args)
code_operator = args.fetch(:operator, nil).to_code
case code_operator.to_s
when "hour"
sig(args)
code_hour
when "hours"
sig(args)
code_hours
when "minute"
sig(args)
code_minute
when "minutes"
sig(args)
code_minutes
when "second"
sig(args)
code_second
when "seconds"
sig(args)
code_seconds
else
super
end
end
|
#code_hour ⇒ Object
87
88
89
|
# File 'lib/code/object/date.rb', line 87
def code_hour
Integer.new(0)
end
|
#code_hours ⇒ Object
91
92
93
|
# File 'lib/code/object/date.rb', line 91
def code_hours
Integer.new(0)
end
|
#code_minute ⇒ Object
95
96
97
|
# File 'lib/code/object/date.rb', line 95
def code_minute
Integer.new(0)
end
|
#code_minutes ⇒ Object
99
100
101
|
# File 'lib/code/object/date.rb', line 99
def code_minutes
Integer.new(0)
end
|
#code_second ⇒ Object
103
104
105
|
# File 'lib/code/object/date.rb', line 103
def code_second
Integer.new(0)
end
|
#code_seconds ⇒ Object
107
108
109
|
# File 'lib/code/object/date.rb', line 107
def code_seconds
Integer.new(0)
end
|