code-ruby 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/object/date.rb +42 -0
- data/lib/code/parser/square_bracket.rb +2 -6
- data/spec/code_spec.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e9396ebb09849d887bc18eb7069427616992d307fa3a556aa24fb330c4c8bf
|
4
|
+
data.tar.gz: b97e8a8c3bacbbed9dd14f5b3de85b11a20db9e66e1974e3bfdb1b2e543227a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c3e38a8a8eaeca2aa543c8128ad083a62f2b93a6b7d32efaf9efbb02a315df957b3ae6516031ec22edc573c3fccc3cd4347ffc582ab4083410b01a1ab2bf117
|
7
|
+
data.tar.gz: 21ad77b0775d8342799f5fbad810fc52e96b4c3d4bfc25154d614afc6fbd8c1561f1ac85cc4be5adf65e96337bb255585ea8449e5dcd6957318ea171f2b9b739
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
data/lib/code/object/date.rb
CHANGED
@@ -22,6 +22,9 @@ class Code
|
|
22
22
|
when "today"
|
23
23
|
sig(args)
|
24
24
|
code_today
|
25
|
+
when "current"
|
26
|
+
sig(args)
|
27
|
+
code_current
|
25
28
|
when "now"
|
26
29
|
sig(args)
|
27
30
|
code_now
|
@@ -47,6 +50,11 @@ class Code
|
|
47
50
|
new(::Time.zone.now.beginning_of_day)
|
48
51
|
end
|
49
52
|
|
53
|
+
def self.code_current
|
54
|
+
::Time.zone ||= Time::DEFAULT_ZONE
|
55
|
+
new(::Time.zone.now.beginning_of_day)
|
56
|
+
end
|
57
|
+
|
50
58
|
def self.code_tomorrow
|
51
59
|
::Time.zone ||= Time::DEFAULT_ZONE
|
52
60
|
new(::Time.zone.tomorrow.beginning_of_day)
|
@@ -59,6 +67,8 @@ class Code
|
|
59
67
|
|
60
68
|
def call(**args)
|
61
69
|
code_operator = args.fetch(:operator, nil).to_code
|
70
|
+
code_arguments = args.fetch(:arguments, []).to_code
|
71
|
+
code_value = code_arguments.code_first
|
62
72
|
|
63
73
|
case code_operator.to_s
|
64
74
|
when "hour"
|
@@ -79,6 +89,24 @@ class Code
|
|
79
89
|
when "seconds"
|
80
90
|
sig(args)
|
81
91
|
code_seconds
|
92
|
+
when "change"
|
93
|
+
sig(args) do
|
94
|
+
{
|
95
|
+
year: (String | Integer).maybe,
|
96
|
+
month: (String | Integer).maybe,
|
97
|
+
day: (String | Integer).maybe,
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
if code_value.nothing?
|
102
|
+
code_change
|
103
|
+
else
|
104
|
+
code_change(
|
105
|
+
year: code_value.code_get(:year),
|
106
|
+
month: code_value.code_get(:month),
|
107
|
+
day: code_value.code_get(:day),
|
108
|
+
)
|
109
|
+
end
|
82
110
|
else
|
83
111
|
super
|
84
112
|
end
|
@@ -107,6 +135,20 @@ class Code
|
|
107
135
|
def code_seconds
|
108
136
|
Integer.new(0)
|
109
137
|
end
|
138
|
+
|
139
|
+
def code_change(year: nil, month: nil, day: nil)
|
140
|
+
code_year = year.to_code
|
141
|
+
code_month = month.to_code
|
142
|
+
code_day = day.to_code
|
143
|
+
|
144
|
+
raw.change(**{
|
145
|
+
year: code_year.raw,
|
146
|
+
month: code_month.raw,
|
147
|
+
day: code_day.raw
|
148
|
+
}.compact)
|
149
|
+
|
150
|
+
self
|
151
|
+
end
|
110
152
|
end
|
111
153
|
end
|
112
154
|
end
|
@@ -7,10 +7,6 @@ class Code
|
|
7
7
|
UnaryMinus
|
8
8
|
end
|
9
9
|
|
10
|
-
def square_bracket
|
11
|
-
SquareBracket
|
12
|
-
end
|
13
|
-
|
14
10
|
def whitespace
|
15
11
|
Whitespace
|
16
12
|
end
|
@@ -30,8 +26,8 @@ class Code
|
|
30
26
|
def root
|
31
27
|
(
|
32
28
|
statement.aka(:left) << (
|
33
|
-
left_square_bracket << whitespace? <<
|
34
|
-
|
29
|
+
left_square_bracket << whitespace? << Statement <<
|
30
|
+
(whitespace? << right_square_bracket).maybe
|
35
31
|
).repeat(1).aka(:statements).maybe
|
36
32
|
)
|
37
33
|
.aka(:square_bracket)
|
data/spec/code_spec.rb
CHANGED