code-ruby 1.5.5 → 1.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/concerns/shared.rb +33 -6
- data/lib/code/node/code.rb +4 -0
- data/lib/code/node/function_parameter.rb +8 -7
- data/lib/code/object/code.rb +1 -1
- data/lib/code/object/date.rb +9 -7
- data/lib/code/object/decimal.rb +14 -24
- data/lib/code/object/dictionary.rb +28 -22
- data/lib/code/object/function.rb +23 -3
- data/lib/code/object/integer.rb +14 -0
- data/lib/code/object/list.rb +50 -1
- data/lib/code/object/parameter.rb +17 -1
- data/lib/code/object/string.rb +7 -0
- data/lib/code/parser/equality.rb +5 -4
- data/lib/code/parser/name.rb +17 -4
- data/lib/code/parser/negation.rb +2 -2
- data/spec/code_spec.rb +139 -118
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44b144b44b3cff354f959404a790db624dd3c57690b9443c596c1a53e3c128ea
|
4
|
+
data.tar.gz: 3443010c854864268a599a9b0383518c560cdfa055d45a9122630b24d8b1b168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 016fa10fc17de26a7bc94ddfbc5281265d1a80f6281de93f2bb4cb7513060230399cfbfa4173526940adf20608de88904fdd9590defd1f8193bd25b720ab227f
|
7
|
+
data.tar.gz: 6469efaf79c5336ddc26c61ab4c015678425222729317fed8f74b1af8dba932ba0189dce090da88430294eec7bd7acecc834854e1ab2c5b466164eb80a2cd027
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.7
|
data/lib/code/concerns/shared.rb
CHANGED
@@ -16,7 +16,7 @@ class Code
|
|
16
16
|
code_new(*code_arguments.raw)
|
17
17
|
when "!", "not"
|
18
18
|
sig(args)
|
19
|
-
|
19
|
+
code_exclamation_mark
|
20
20
|
when "!=", "different"
|
21
21
|
sig(args) { Object }
|
22
22
|
code_different(code_value)
|
@@ -34,10 +34,13 @@ class Code
|
|
34
34
|
code_exclusive_range(code_value)
|
35
35
|
when "==", "equal"
|
36
36
|
sig(args) { Object }
|
37
|
-
|
37
|
+
code_equal(code_value)
|
38
38
|
when "===", "strict_equal"
|
39
39
|
sig(args) { Object }
|
40
|
-
|
40
|
+
code_strict_equal(code_value)
|
41
|
+
when "!==", "strict_different"
|
42
|
+
sig(args) { Object }
|
43
|
+
code_strict_different(code_value)
|
41
44
|
when "falsy?"
|
42
45
|
sig(args)
|
43
46
|
code_falsy?
|
@@ -109,6 +112,12 @@ class Code
|
|
109
112
|
when "name"
|
110
113
|
sig(args)
|
111
114
|
code_name
|
115
|
+
when "nothing?"
|
116
|
+
sig(args)
|
117
|
+
code_nothing?
|
118
|
+
when "something?"
|
119
|
+
sig(args)
|
120
|
+
code_something?
|
112
121
|
when /=$/
|
113
122
|
sig(args) { Object }
|
114
123
|
|
@@ -166,13 +175,13 @@ class Code
|
|
166
175
|
Object::Boolean.new(self != code_other)
|
167
176
|
end
|
168
177
|
|
169
|
-
def
|
178
|
+
def code_equal(other)
|
170
179
|
code_other = other.to_code
|
171
180
|
|
172
181
|
Object::Boolean.new(self == code_other)
|
173
182
|
end
|
174
183
|
|
175
|
-
def
|
184
|
+
def code_exclamation_mark
|
176
185
|
Object::Boolean.new(falsy?)
|
177
186
|
end
|
178
187
|
|
@@ -198,12 +207,18 @@ class Code
|
|
198
207
|
self
|
199
208
|
end
|
200
209
|
|
201
|
-
def
|
210
|
+
def code_strict_equal(other)
|
202
211
|
code_other = other.to_code
|
203
212
|
|
204
213
|
Object::Boolean.new(self === code_other)
|
205
214
|
end
|
206
215
|
|
216
|
+
def code_strict_different(other)
|
217
|
+
code_other = other.to_code
|
218
|
+
|
219
|
+
Object::Boolean.new(!(self === code_other))
|
220
|
+
end
|
221
|
+
|
207
222
|
def falsy?
|
208
223
|
!truthy?
|
209
224
|
end
|
@@ -302,10 +317,22 @@ class Code
|
|
302
317
|
code_inspect.raw
|
303
318
|
end
|
304
319
|
|
320
|
+
def code_nothing?
|
321
|
+
Boolean.new(nothing?)
|
322
|
+
end
|
323
|
+
|
324
|
+
def code_something?
|
325
|
+
Boolean.new(something?)
|
326
|
+
end
|
327
|
+
|
305
328
|
def nothing?
|
306
329
|
false
|
307
330
|
end
|
308
331
|
|
332
|
+
def something?
|
333
|
+
!nothing?
|
334
|
+
end
|
335
|
+
|
309
336
|
def code_falsy?
|
310
337
|
Object::Boolean.new(falsy?)
|
311
338
|
end
|
data/lib/code/node/code.rb
CHANGED
@@ -3,11 +3,16 @@
|
|
3
3
|
class Code
|
4
4
|
class Node
|
5
5
|
class FunctionParameter < Node
|
6
|
+
attr_reader :default
|
7
|
+
|
6
8
|
def initialize(parsed)
|
7
9
|
return if parsed.blank?
|
8
10
|
|
9
11
|
@name = parsed.delete(:name).presence
|
10
12
|
@keyword = parsed.delete(:keyword).present?
|
13
|
+
@regular_splat = parsed.delete(:regular_splat).present?
|
14
|
+
@keyword_splat = parsed.delete(:keyword_splat).present?
|
15
|
+
@default = Code.new(parsed.delete(:default)) if parsed.key?(:default)
|
11
16
|
end
|
12
17
|
|
13
18
|
def name
|
@@ -23,15 +28,11 @@ class Code
|
|
23
28
|
end
|
24
29
|
|
25
30
|
def regular_splat?
|
26
|
-
|
31
|
+
!!@regular_splat
|
27
32
|
end
|
28
33
|
|
29
34
|
def keyword_splat?
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def default
|
34
|
-
nil
|
35
|
+
!!@keyword_splat
|
35
36
|
end
|
36
37
|
|
37
38
|
def to_h
|
@@ -41,7 +42,7 @@ class Code
|
|
41
42
|
keyword?: keyword?,
|
42
43
|
regular_splat?: regular_splat?,
|
43
44
|
keyword_splat?: keyword_splat?,
|
44
|
-
default:
|
45
|
+
default: default
|
45
46
|
}
|
46
47
|
end
|
47
48
|
|
data/lib/code/object/code.rb
CHANGED
data/lib/code/object/date.rb
CHANGED
@@ -141,13 +141,15 @@ class Code
|
|
141
141
|
code_month = month.to_code
|
142
142
|
code_day = day.to_code
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
144
|
+
if code_year.something? || code_month.something? || code_day.something?
|
145
|
+
raw.change(
|
146
|
+
**{
|
147
|
+
year: code_year.raw,
|
148
|
+
month: code_month.raw,
|
149
|
+
day: code_day.raw
|
150
|
+
}.compact
|
151
|
+
)
|
152
|
+
end
|
151
153
|
|
152
154
|
self
|
153
155
|
end
|
data/lib/code/object/decimal.rb
CHANGED
@@ -75,9 +75,6 @@ class Code
|
|
75
75
|
when "ceil"
|
76
76
|
sig(args) { Integer.maybe }
|
77
77
|
code_ceil(code_value)
|
78
|
-
when "clone"
|
79
|
-
sig(args)
|
80
|
-
code_clone
|
81
78
|
when "eight?"
|
82
79
|
sig(args)
|
83
80
|
code_eight?
|
@@ -114,15 +111,6 @@ class Code
|
|
114
111
|
when "three?"
|
115
112
|
sig(args)
|
116
113
|
code_three?
|
117
|
-
when "to_decimal"
|
118
|
-
sig(args)
|
119
|
-
code_to_decimal
|
120
|
-
when "to_integer"
|
121
|
-
sig(args)
|
122
|
-
code_to_integer
|
123
|
-
when "to_string"
|
124
|
-
sig(args)
|
125
|
-
code_to_string
|
126
114
|
when "truncate"
|
127
115
|
sig(args) { Integer.maybe }
|
128
116
|
code_truncate(code_value)
|
@@ -135,6 +123,12 @@ class Code
|
|
135
123
|
when "|", "bitwise_or"
|
136
124
|
sig(args) { Integer | Decimal }
|
137
125
|
code_bitwise_or(code_value)
|
126
|
+
when "many?"
|
127
|
+
sig(args)
|
128
|
+
code_many?
|
129
|
+
when "any?"
|
130
|
+
sig(args)
|
131
|
+
code_any?
|
138
132
|
else
|
139
133
|
super
|
140
134
|
end
|
@@ -169,10 +163,6 @@ class Code
|
|
169
163
|
Decimal.new(raw.ceil(code_n.raw))
|
170
164
|
end
|
171
165
|
|
172
|
-
def code_clone
|
173
|
-
Decimal.new(raw)
|
174
|
-
end
|
175
|
-
|
176
166
|
def code_compare(other)
|
177
167
|
code_other = other.to_code
|
178
168
|
|
@@ -309,14 +299,6 @@ class Code
|
|
309
299
|
Boolean.new(raw == 3)
|
310
300
|
end
|
311
301
|
|
312
|
-
def code_to_decimal
|
313
|
-
Decimal.new(raw)
|
314
|
-
end
|
315
|
-
|
316
|
-
def code_to_integer
|
317
|
-
Integer.new(raw.to_i)
|
318
|
-
end
|
319
|
-
|
320
302
|
def code_to_string
|
321
303
|
String.new(raw.to_s("F"))
|
322
304
|
end
|
@@ -339,6 +321,14 @@ class Code
|
|
339
321
|
def code_zero?
|
340
322
|
Boolean.new(raw.zero?)
|
341
323
|
end
|
324
|
+
|
325
|
+
def code_many?
|
326
|
+
Boolean.new(raw > 1)
|
327
|
+
end
|
328
|
+
|
329
|
+
def code_any?
|
330
|
+
Boolean.new(raw > 0)
|
331
|
+
end
|
342
332
|
end
|
343
333
|
end
|
344
334
|
end
|
@@ -14,6 +14,7 @@ class Code
|
|
14
14
|
delegate :code_three?, to: :code_size
|
15
15
|
delegate :code_two?, to: :code_size
|
16
16
|
delegate :code_zero?, to: :code_size
|
17
|
+
delegate :code_many?, to: :code_size
|
17
18
|
|
18
19
|
def initialize(*args, **kargs, &_block)
|
19
20
|
self.raw =
|
@@ -59,7 +60,7 @@ class Code
|
|
59
60
|
sig(args) { Object }
|
60
61
|
code_get(code_value)
|
61
62
|
when "any?"
|
62
|
-
sig(args) { Function | Class }
|
63
|
+
sig(args) { (Function | Class).maybe }
|
63
64
|
code_any?(code_value, **globals)
|
64
65
|
when "clear"
|
65
66
|
sig(args)
|
@@ -163,9 +164,6 @@ class Code
|
|
163
164
|
when "three?"
|
164
165
|
sig(args)
|
165
166
|
code_three?
|
166
|
-
when "to_list"
|
167
|
-
sig(args)
|
168
|
-
code_to_list
|
169
167
|
when "transform_values"
|
170
168
|
sig(args) { Function }
|
171
169
|
code_transform_values(code_value, **globals)
|
@@ -181,6 +179,9 @@ class Code
|
|
181
179
|
when "zero?"
|
182
180
|
sig(args)
|
183
181
|
code_zero?
|
182
|
+
when "many?"
|
183
|
+
sig(args)
|
184
|
+
code_many?
|
184
185
|
when ->(code_operator) { code_has_key?(code_operator).truthy? }
|
185
186
|
result = code_fetch(code_operator)
|
186
187
|
|
@@ -198,7 +199,9 @@ class Code
|
|
198
199
|
def code_any?(argument, **globals)
|
199
200
|
code_argument = argument.to_code
|
200
201
|
|
201
|
-
if code_argument.
|
202
|
+
if code_argument.nothing?
|
203
|
+
Boolean.new(raw.any?)
|
204
|
+
elsif code_argument.is_a?(Class)
|
202
205
|
Boolean.new(raw.any? { |_, value| value.is_a?(code_argument.raw) })
|
203
206
|
else
|
204
207
|
index = 0
|
@@ -207,7 +210,7 @@ class Code
|
|
207
210
|
raw.any? do |key, value|
|
208
211
|
code_argument
|
209
212
|
.call(
|
210
|
-
arguments: List.new([key, value,
|
213
|
+
arguments: List.new([key, value, Integer.new(index), self]),
|
211
214
|
**globals
|
212
215
|
)
|
213
216
|
.truthy?
|
@@ -254,7 +257,7 @@ class Code
|
|
254
257
|
Nothing.new
|
255
258
|
else
|
256
259
|
code_default.call(
|
257
|
-
arguments: List.new([code_first,
|
260
|
+
arguments: List.new([code_first, code_index, self]),
|
258
261
|
**globals
|
259
262
|
)
|
260
263
|
end
|
@@ -295,7 +298,7 @@ class Code
|
|
295
298
|
raw.delete_if.with_index do |(code_key, code_value), index|
|
296
299
|
argument.call(
|
297
300
|
arguments:
|
298
|
-
List.new([code_key, code_value,
|
301
|
+
List.new([code_key, code_value, Integer.new(index), self]),
|
299
302
|
**globals
|
300
303
|
).truthy?
|
301
304
|
end
|
@@ -312,7 +315,7 @@ class Code
|
|
312
315
|
else
|
313
316
|
raw.delete_if.with_index do |(key, value), index|
|
314
317
|
code_argument.call(
|
315
|
-
arguments: List.new([key, value,
|
318
|
+
arguments: List.new([key, value, Integer.new(index), self]),
|
316
319
|
**globals
|
317
320
|
).falsy?
|
318
321
|
end
|
@@ -340,7 +343,7 @@ class Code
|
|
340
343
|
|
341
344
|
raw.each.with_index do |(key, value), index|
|
342
345
|
code_argument.call(
|
343
|
-
arguments: List.new([key, value,
|
346
|
+
arguments: List.new([key, value, Integer.new(index), self]),
|
344
347
|
**globals
|
345
348
|
)
|
346
349
|
end
|
@@ -647,10 +650,6 @@ class Code
|
|
647
650
|
Context.new(raw)
|
648
651
|
end
|
649
652
|
|
650
|
-
def code_to_list
|
651
|
-
List.new(raw.to_a.map { |key_value| List.new(key_value) })
|
652
|
-
end
|
653
|
-
|
654
653
|
def code_to_query(namespace = nil)
|
655
654
|
code_namespace = namespace.to_code
|
656
655
|
|
@@ -661,14 +660,21 @@ class Code
|
|
661
660
|
code_function = function.to_code
|
662
661
|
|
663
662
|
Dictionary.new(
|
664
|
-
raw
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
663
|
+
raw
|
664
|
+
.map
|
665
|
+
.with_index do |(key, value), index|
|
666
|
+
[
|
667
|
+
key.to_code,
|
668
|
+
code_function.call(
|
669
|
+
arguments:
|
670
|
+
List.new([key.to_code, value.to_code, index.to_code, self]),
|
671
|
+
**globals
|
672
|
+
)
|
673
|
+
]
|
674
|
+
rescue Error::Next => e
|
675
|
+
[key.to_code, e.code_value]
|
676
|
+
end
|
677
|
+
.to_h
|
672
678
|
)
|
673
679
|
end
|
674
680
|
|
data/lib/code/object/function.rb
CHANGED
@@ -38,7 +38,13 @@ class Code
|
|
38
38
|
|
39
39
|
code_parameters.raw.each.with_index do |code_parameter, index|
|
40
40
|
code_argument =
|
41
|
-
if code_parameter.
|
41
|
+
if code_parameter.regular_splat?
|
42
|
+
code_arguments
|
43
|
+
elsif code_parameter.keyword_splat?
|
44
|
+
code_arguments.raw.detect do |code_argument|
|
45
|
+
code_argument.is_a?(Dictionary)
|
46
|
+
end || Dictionary.new
|
47
|
+
elsif code_parameter.keyword?
|
42
48
|
code_arguments
|
43
49
|
.raw
|
44
50
|
.select { |code_argument| code_argument.is_a?(Dictionary) }
|
@@ -46,6 +52,7 @@ class Code
|
|
46
52
|
code_dictionary.code_has_value?(parameter.code_name).truthy?
|
47
53
|
end
|
48
54
|
&.code_get(parameter.code_name)
|
55
|
+
.to_code
|
49
56
|
else
|
50
57
|
code_arguments.raw[index].to_code
|
51
58
|
end
|
@@ -64,15 +71,28 @@ class Code
|
|
64
71
|
code_parameters
|
65
72
|
.raw
|
66
73
|
.inject([]) do |signature, code_parameter|
|
67
|
-
if code_parameter.
|
74
|
+
if code_parameter.keyword_splat?
|
75
|
+
signature + [Dictionary.maybe]
|
76
|
+
elsif code_parameter.regular_splat?
|
77
|
+
signature + [Object.repeat]
|
78
|
+
elsif code_parameter.keyword? && code_parameter.required?
|
68
79
|
if signature.last.is_a?(::Hash)
|
69
80
|
signature.last[code_parameter.code_name] = Object
|
70
81
|
signature
|
71
82
|
else
|
72
83
|
signature + [{ code_parameter.code_name => Object }]
|
73
84
|
end
|
74
|
-
|
85
|
+
elsif code_parameter.keyword?
|
86
|
+
if signature.last.is_a?(::Hash)
|
87
|
+
signature.last[code_parameter.code_name] = Object.maybe
|
88
|
+
signature
|
89
|
+
else
|
90
|
+
signature + [{ code_parameter.code_name => Object.maybe }]
|
91
|
+
end
|
92
|
+
elsif code_parameter.required?
|
75
93
|
signature + [Object]
|
94
|
+
else
|
95
|
+
signature + [Object.maybe]
|
76
96
|
end
|
77
97
|
end + [Object.repeat]
|
78
98
|
end
|
data/lib/code/object/integer.rb
CHANGED
@@ -154,6 +154,12 @@ class Code
|
|
154
154
|
when "|", "bitwise_or"
|
155
155
|
sig(args) { Integer | Decimal }
|
156
156
|
code_bitwise_or(code_value)
|
157
|
+
when "many?"
|
158
|
+
sig(args)
|
159
|
+
code_many?
|
160
|
+
when "any?"
|
161
|
+
sig(args)
|
162
|
+
code_any?
|
157
163
|
else
|
158
164
|
super
|
159
165
|
end
|
@@ -411,6 +417,14 @@ class Code
|
|
411
417
|
Boolean.new(raw.zero?)
|
412
418
|
end
|
413
419
|
|
420
|
+
def code_many?
|
421
|
+
Boolean.new(raw > 1)
|
422
|
+
end
|
423
|
+
|
424
|
+
def code_any?
|
425
|
+
Boolean.new(raw > 0)
|
426
|
+
end
|
427
|
+
|
414
428
|
def code_hours
|
415
429
|
Duration.new(raw.hours)
|
416
430
|
end
|
data/lib/code/object/list.rb
CHANGED
@@ -3,6 +3,19 @@
|
|
3
3
|
class Code
|
4
4
|
class Object
|
5
5
|
class List < Object
|
6
|
+
delegate :code_eight?, to: :code_size
|
7
|
+
delegate :code_five?, to: :code_size
|
8
|
+
delegate :code_four?, to: :code_size
|
9
|
+
delegate :code_nine?, to: :code_size
|
10
|
+
delegate :code_one?, to: :code_size
|
11
|
+
delegate :code_seven?, to: :code_size
|
12
|
+
delegate :code_six?, to: :code_size
|
13
|
+
delegate :code_ten?, to: :code_size
|
14
|
+
delegate :code_three?, to: :code_size
|
15
|
+
delegate :code_two?, to: :code_size
|
16
|
+
delegate :code_zero?, to: :code_size
|
17
|
+
delegate :code_many?, to: :code_size
|
18
|
+
|
6
19
|
def initialize(*args, **_kargs, &_block)
|
7
20
|
self.raw =
|
8
21
|
if args.first.is_a?(List)
|
@@ -114,6 +127,42 @@ class Code
|
|
114
127
|
when "uniq"
|
115
128
|
sig(args)
|
116
129
|
code_uniq
|
130
|
+
when "zero?"
|
131
|
+
sig(args)
|
132
|
+
code_zero?
|
133
|
+
when "one?"
|
134
|
+
sig(args)
|
135
|
+
code_one?
|
136
|
+
when "two?"
|
137
|
+
sig(args)
|
138
|
+
code_two?
|
139
|
+
when "three?"
|
140
|
+
sig(args)
|
141
|
+
code_three?
|
142
|
+
when "four?"
|
143
|
+
sig(args)
|
144
|
+
code_four?
|
145
|
+
when "five?"
|
146
|
+
sig(args)
|
147
|
+
code_five?
|
148
|
+
when "six?"
|
149
|
+
sig(args)
|
150
|
+
code_six?
|
151
|
+
when "seven?"
|
152
|
+
sig(args)
|
153
|
+
code_seven?
|
154
|
+
when "eight?"
|
155
|
+
sig(args)
|
156
|
+
code_eight?
|
157
|
+
when "nine?"
|
158
|
+
sig(args)
|
159
|
+
code_nine?
|
160
|
+
when "ten?"
|
161
|
+
sig(args)
|
162
|
+
code_ten?
|
163
|
+
when "many?"
|
164
|
+
sig(args)
|
165
|
+
code_many?
|
117
166
|
else
|
118
167
|
super
|
119
168
|
end
|
@@ -479,7 +528,7 @@ class Code
|
|
479
528
|
def code_get(argument)
|
480
529
|
code_argument = argument.to_code
|
481
530
|
|
482
|
-
raw[code_argument] || Nothing.new
|
531
|
+
raw[code_argument.raw] || Nothing.new
|
483
532
|
end
|
484
533
|
|
485
534
|
def code_set(key, value)
|
@@ -27,14 +27,30 @@ class Code
|
|
27
27
|
Boolean.new(raw.code_get(:keyword_splat?))
|
28
28
|
end
|
29
29
|
|
30
|
+
def code_required?
|
31
|
+
code_default.code_falsy?
|
32
|
+
end
|
33
|
+
|
34
|
+
def code_optional?
|
35
|
+
code_default.code_truthy?
|
36
|
+
end
|
37
|
+
|
30
38
|
def code_default
|
31
|
-
|
39
|
+
raw.code_get(:default).to_code
|
32
40
|
end
|
33
41
|
|
34
42
|
def code_evaluate(...)
|
35
43
|
code_default.code_evaluate(...)
|
36
44
|
end
|
37
45
|
|
46
|
+
def required?
|
47
|
+
code_required?.truthy?
|
48
|
+
end
|
49
|
+
|
50
|
+
def optional?
|
51
|
+
code_optional?.truthy?
|
52
|
+
end
|
53
|
+
|
38
54
|
def regular?
|
39
55
|
code_regular?.truthy?
|
40
56
|
end
|
data/lib/code/object/string.rb
CHANGED
@@ -52,6 +52,9 @@ class Code
|
|
52
52
|
when "substitute"
|
53
53
|
sig(args) { [String, String.maybe] }
|
54
54
|
code_substitute(*code_arguments.raw)
|
55
|
+
when "upcase"
|
56
|
+
sig(args)
|
57
|
+
code_upcase
|
55
58
|
else
|
56
59
|
super
|
57
60
|
end
|
@@ -61,6 +64,10 @@ class Code
|
|
61
64
|
String.new(raw.downcase)
|
62
65
|
end
|
63
66
|
|
67
|
+
def code_upcase
|
68
|
+
String.new(raw.upcase)
|
69
|
+
end
|
70
|
+
|
64
71
|
def code_include?(value)
|
65
72
|
code_value = value.to_code
|
66
73
|
Boolean.new(raw.include?(code_value.raw))
|
data/lib/code/parser/equality.rb
CHANGED
@@ -19,7 +19,7 @@ class Code
|
|
19
19
|
str("<")
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def exclamation_mark
|
23
23
|
str("!")
|
24
24
|
end
|
25
25
|
|
@@ -32,9 +32,10 @@ class Code
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def operator
|
35
|
-
(
|
36
|
-
(
|
37
|
-
(
|
35
|
+
(exclamation_mark << equal << equal) | (equal << equal << equal) |
|
36
|
+
(equal << equal) | (lesser << equal << greater) |
|
37
|
+
(exclamation_mark << equal) | (equal << tilde) | (tilde << equal) |
|
38
|
+
(exclamation_mark << tilde)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/code/parser/name.rb
CHANGED
@@ -99,7 +99,15 @@ class Code
|
|
99
99
|
str("else")
|
100
100
|
end
|
101
101
|
|
102
|
-
def
|
102
|
+
def exclamation_mark
|
103
|
+
str("!")
|
104
|
+
end
|
105
|
+
|
106
|
+
def question_mark
|
107
|
+
str("?")
|
108
|
+
end
|
109
|
+
|
110
|
+
def reserved_character
|
103
111
|
ampersand | equal | pipe | dot | colon | comma | space | newline |
|
104
112
|
opening_curly_bracket | closing_curly_bracket | opening_parenthesis |
|
105
113
|
closing_parenthesis | opening_square_bracket |
|
@@ -108,11 +116,15 @@ class Code
|
|
108
116
|
end
|
109
117
|
|
110
118
|
def character
|
111
|
-
|
119
|
+
reserved_character.absent << any
|
112
120
|
end
|
113
121
|
|
114
122
|
def separator
|
115
|
-
|
123
|
+
reserved_character | any.absent
|
124
|
+
end
|
125
|
+
|
126
|
+
def special_characters
|
127
|
+
exclamation_mark | question_mark
|
116
128
|
end
|
117
129
|
|
118
130
|
def root
|
@@ -120,7 +132,8 @@ class Code
|
|
120
132
|
begin_keyword << separator
|
121
133
|
).absent << (else_keyword << separator).absent <<
|
122
134
|
(elsif_keyword << separator).absent <<
|
123
|
-
(end_keyword << separator).absent <<
|
135
|
+
(end_keyword << separator).absent <<
|
136
|
+
special_characters.absent << character.repeat(1)
|
124
137
|
end
|
125
138
|
end
|
126
139
|
end
|
data/lib/code/parser/negation.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
class Code
|
4
4
|
class Parser
|
5
5
|
class Negation < Language
|
6
|
-
def
|
6
|
+
def exclamation_mark
|
7
7
|
str("!")
|
8
8
|
end
|
9
9
|
|
@@ -16,7 +16,7 @@ class Code
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def operator
|
19
|
-
|
19
|
+
exclamation_mark | tilde | plus
|
20
20
|
end
|
21
21
|
|
22
22
|
def negation
|
data/spec/code_spec.rb
CHANGED
@@ -4,124 +4,145 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
RSpec.describe Code do
|
6
6
|
(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
7
|
+
[
|
8
|
+
"{ a: 1, b: 2 }.transform_values { |key| key.upcase }",
|
9
|
+
"{ a: { b: [1, 2, 3, 4] } }.dig(:a, :b, 2)",
|
10
|
+
"{ a: 1, b: 2 }.transform_values { |key, value, index| index * 2 }",
|
11
|
+
"{ a: 1, b: 2 }.transform_values { |key, value, index, dictionary| dictionary.a }",
|
12
|
+
"sum = (a, b: 2) => { a + b } sum(1)",
|
13
|
+
"Object.new !== Object.new"
|
14
|
+
] +
|
15
|
+
%w[
|
16
|
+
Date.new.change
|
17
|
+
{}.zero?
|
18
|
+
{}.any?
|
19
|
+
{}.many?
|
20
|
+
1.zero?
|
21
|
+
1.any?
|
22
|
+
1.many?
|
23
|
+
1.0.zero?
|
24
|
+
1.0.any?
|
25
|
+
1.0.many?
|
26
|
+
[].zero?
|
27
|
+
[].any?
|
28
|
+
[].many?
|
29
|
+
Base64
|
30
|
+
Base64.new
|
31
|
+
Smtp
|
32
|
+
Smtp.new
|
33
|
+
Time.monday?
|
34
|
+
Time.tuesday?
|
35
|
+
Time.wednesday?
|
36
|
+
Time.thursday?
|
37
|
+
Time.friday?
|
38
|
+
Time.saturday?
|
39
|
+
Time.sunday?
|
40
|
+
Time.now.monday?
|
41
|
+
Time.now.tuesday?
|
42
|
+
Time.now.wednesday?
|
43
|
+
Time.now.thursday?
|
44
|
+
Time.now.friday?
|
45
|
+
Time.now.saturday?
|
46
|
+
Time.now.sunday?
|
47
|
+
Time.now.second
|
48
|
+
Time.now.seconds
|
49
|
+
Time.now.minute
|
50
|
+
Time.now.minutes
|
51
|
+
Time.now.hour
|
52
|
+
Time.now.hours
|
53
|
+
Time.now.day
|
54
|
+
Time.now.days
|
55
|
+
Time.now.month
|
56
|
+
Time.now.months
|
57
|
+
Time.now.year
|
58
|
+
Time.now.years
|
59
|
+
Time.second
|
60
|
+
Time.seconds
|
61
|
+
Time.minute
|
62
|
+
Time.minutes
|
63
|
+
Time.hour
|
64
|
+
Time.hours
|
65
|
+
Time.day
|
66
|
+
Time.days
|
67
|
+
Time.month
|
68
|
+
Time.months
|
69
|
+
Time.year
|
70
|
+
Time.years
|
71
|
+
1.day.ago
|
72
|
+
1.day.from_now
|
73
|
+
1.hour.ago
|
74
|
+
1.hour.from_now
|
75
|
+
2.days.ago
|
76
|
+
2.days.from_now
|
77
|
+
2.hours.ago
|
78
|
+
2.hours.ago.hour
|
79
|
+
2.hours.from_now
|
80
|
+
2.hours.from_now.hour
|
81
|
+
Time.hour
|
82
|
+
Date.hour
|
83
|
+
Boolean.new
|
84
|
+
Boolean.new(true)
|
85
|
+
Boolean.new(false)
|
86
|
+
Class.new
|
87
|
+
Class.new(Boolean)
|
88
|
+
Class.new(Class)
|
89
|
+
Context.new
|
90
|
+
Context.new(a:1)
|
91
|
+
Date.new
|
92
|
+
Date.new.hour
|
93
|
+
Date.new("2024-03-05")
|
94
|
+
Date.new("2024-03-05").hour
|
95
|
+
Date.today
|
96
|
+
Date.yesterday
|
97
|
+
Date.tomorrow
|
98
|
+
Date.tomorrow.hour
|
99
|
+
Decimal.new
|
100
|
+
Decimal.new(0)
|
101
|
+
Decimal.new(1.2)
|
102
|
+
Dictionary.new
|
103
|
+
Dictionary.new(a:1)
|
104
|
+
Duration.new
|
105
|
+
Duration.new(1.day)
|
106
|
+
Duration.new("P1D")
|
107
|
+
Function.new
|
108
|
+
Integer.new
|
109
|
+
Integer.new(0)
|
110
|
+
Integer.new(1)
|
111
|
+
Integer.new(1.2)
|
112
|
+
List.new
|
113
|
+
List.new([])
|
114
|
+
List.new([1,2])
|
115
|
+
Nothing.new
|
116
|
+
Nothing.new(1)
|
117
|
+
Object.new
|
118
|
+
Object.new(1)
|
119
|
+
Range.new
|
120
|
+
Range.new(1,2)
|
121
|
+
Range.new(-1)
|
122
|
+
Range.new(1,2,exclude_end:false)
|
123
|
+
Range.new(1,2,exclude_end:true)
|
124
|
+
String.new
|
125
|
+
String.new(:hello)
|
126
|
+
Time.new
|
127
|
+
Time.new("2024-03-05.06:10:59.UTC")
|
128
|
+
Time.now
|
129
|
+
Time.tomorrow
|
130
|
+
Time.yesterday
|
131
|
+
Time.tomorrow
|
132
|
+
Code.new
|
133
|
+
Parameter.new
|
134
|
+
IdentifierList.new
|
135
|
+
IdentifierList.new([])
|
136
|
+
Time.new(nothing).before?
|
137
|
+
Html.link_to
|
138
|
+
Html.link_to('/')
|
139
|
+
Html.link_to('Home','/')
|
140
|
+
Json.parse('1')
|
141
|
+
Json.parse('[]')
|
142
|
+
Json.parse('{}')
|
143
|
+
Json.parse('random-string')
|
144
|
+
{}["".to_string]
|
145
|
+
] + ["Time.hour >= 6 and Time.hour <= 23"]
|
125
146
|
).each { |input| it(input) { described_class.evaluate(input) } }
|
126
147
|
|
127
148
|
[
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-06-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|