code-ruby 1.5.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a866affca8019509c1e7836990f7a3488990e5bf64f8c8e3b6a976ed7e1bab6
4
- data.tar.gz: 23ad1030abf7de9981adcf65267c195b85d1026995aa74fa566427c4c74660c5
3
+ metadata.gz: 44b144b44b3cff354f959404a790db624dd3c57690b9443c596c1a53e3c128ea
4
+ data.tar.gz: 3443010c854864268a599a9b0383518c560cdfa055d45a9122630b24d8b1b168
5
5
  SHA512:
6
- metadata.gz: 9b9b495235c6b7e32d00ae42b372c5b42e6a12123d8adda974044d7eceee36a5d802a68c72c52b9926b295b00ea803bb696697bf6377dcad370f539d23f3cc4c
7
- data.tar.gz: be2c356e043c80850ac786da56ec5a380fc624d75f953eedc18817728e70d31f75d4c3e2be5782808da8e50c4c0d445ae6ac9ee150166262d7809f2ea72d1423
6
+ metadata.gz: 016fa10fc17de26a7bc94ddfbc5281265d1a80f6281de93f2bb4cb7513060230399cfbfa4173526940adf20608de88904fdd9590defd1f8193bd25b720ab227f
7
+ data.tar.gz: 6469efaf79c5336ddc26c61ab4c015678425222729317fed8f74b1af8dba932ba0189dce090da88430294eec7bd7acecc834854e1ab2c5b466164eb80a2cd027
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.5.6)
4
+ code-ruby (1.5.7)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.6
1
+ 1.5.7
@@ -16,7 +16,7 @@ class Code
16
16
  code_new(*code_arguments.raw)
17
17
  when "!", "not"
18
18
  sig(args)
19
- code_exclamation_point
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
- code_equal_equal(code_value)
37
+ code_equal(code_value)
38
38
  when "===", "strict_equal"
39
39
  sig(args) { Object }
40
- code_equal_equal_equal(code_value)
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 code_equal_equal(other)
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 code_exclamation_point
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 code_equal_equal_equal(other)
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
@@ -141,13 +141,15 @@ class Code
141
141
  code_month = month.to_code
142
142
  code_day = day.to_code
143
143
 
144
- raw.change(
145
- **{
146
- year: code_year.raw,
147
- month: code_month.raw,
148
- day: code_day.raw
149
- }.compact
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
@@ -210,7 +210,7 @@ class Code
210
210
  raw.any? do |key, value|
211
211
  code_argument
212
212
  .call(
213
- arguments: List.new([key, value, self, Integer.new(index)]),
213
+ arguments: List.new([key, value, Integer.new(index), self]),
214
214
  **globals
215
215
  )
216
216
  .truthy?
@@ -257,7 +257,7 @@ class Code
257
257
  Nothing.new
258
258
  else
259
259
  code_default.call(
260
- arguments: List.new([code_first, self, code_index]),
260
+ arguments: List.new([code_first, code_index, self]),
261
261
  **globals
262
262
  )
263
263
  end
@@ -298,7 +298,7 @@ class Code
298
298
  raw.delete_if.with_index do |(code_key, code_value), index|
299
299
  argument.call(
300
300
  arguments:
301
- List.new([code_key, code_value, self, Integer.new(index)]),
301
+ List.new([code_key, code_value, Integer.new(index), self]),
302
302
  **globals
303
303
  ).truthy?
304
304
  end
@@ -315,7 +315,7 @@ class Code
315
315
  else
316
316
  raw.delete_if.with_index do |(key, value), index|
317
317
  code_argument.call(
318
- arguments: List.new([key, value, self, Integer.new(index)]),
318
+ arguments: List.new([key, value, Integer.new(index), self]),
319
319
  **globals
320
320
  ).falsy?
321
321
  end
@@ -343,7 +343,7 @@ class Code
343
343
 
344
344
  raw.each.with_index do |(key, value), index|
345
345
  code_argument.call(
346
- arguments: List.new([key, value, self, Integer.new(index)]),
346
+ arguments: List.new([key, value, Integer.new(index), self]),
347
347
  **globals
348
348
  )
349
349
  end
@@ -660,17 +660,21 @@ class Code
660
660
  code_function = function.to_code
661
661
 
662
662
  Dictionary.new(
663
- raw.map.with_index do |(key, value), index|
664
- [
665
- key.to_code,
666
- code_function.call(
667
- arguments: List.new([key.to_code, value.to_code, index.to_code, self]),
668
- **globals
669
- )
670
- ]
671
- rescue Error::Next => e
672
- [key.to_code, e.code_value]
673
- end.to_h
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
674
678
  )
675
679
  end
676
680
 
@@ -41,9 +41,9 @@ class Code
41
41
  if code_parameter.regular_splat?
42
42
  code_arguments
43
43
  elsif code_parameter.keyword_splat?
44
- code_arguments
45
- .raw
46
- .detect { |code_argument| code_argument.is_a?(Dictionary) } || Dictionary.new
44
+ code_arguments.raw.detect do |code_argument|
45
+ code_argument.is_a?(Dictionary)
46
+ end || Dictionary.new
47
47
  elsif code_parameter.keyword?
48
48
  code_arguments
49
49
  .raw
@@ -52,6 +52,7 @@ class Code
52
52
  code_dictionary.code_has_value?(parameter.code_name).truthy?
53
53
  end
54
54
  &.code_get(parameter.code_name)
55
+ .to_code
55
56
  else
56
57
  code_arguments.raw[index].to_code
57
58
  end
@@ -528,7 +528,7 @@ class Code
528
528
  def code_get(argument)
529
529
  code_argument = argument.to_code
530
530
 
531
- raw[code_argument] || Nothing.new
531
+ raw[code_argument.raw] || Nothing.new
532
532
  end
533
533
 
534
534
  def code_set(key, value)
@@ -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))
@@ -19,7 +19,7 @@ class Code
19
19
  str("<")
20
20
  end
21
21
 
22
- def exclamation_point
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
- (equal << equal << equal) | (equal << equal) |
36
- (lesser << equal << greater) | (exclamation_point << equal) |
37
- (equal << tilde) | (tilde << equal) | (exclamation_point << tilde)
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
@@ -99,7 +99,15 @@ class Code
99
99
  str("else")
100
100
  end
101
101
 
102
- def special_character
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
- special_character.absent << any
119
+ reserved_character.absent << any
112
120
  end
113
121
 
114
122
  def separator
115
- special_character | any.absent
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 << character.repeat(1)
135
+ (end_keyword << separator).absent <<
136
+ special_characters.absent << character.repeat(1)
124
137
  end
125
138
  end
126
139
  end
@@ -3,7 +3,7 @@
3
3
  class Code
4
4
  class Parser
5
5
  class Negation < Language
6
- def exclamation_point
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
- exclamation_point | tilde | plus
19
+ exclamation_mark | tilde | plus
20
20
  end
21
21
 
22
22
  def negation
data/spec/code_spec.rb CHANGED
@@ -4,136 +4,145 @@ require "spec_helper"
4
4
 
5
5
  RSpec.describe Code do
6
6
  (
7
- %w[
8
- {}.zero?
9
- {}.any?
10
- {}.many?
11
- 1.zero?
12
- 1.any?
13
- 1.many?
14
- 1.0.zero?
15
- 1.0.any?
16
- 1.0.many?
17
- [].zero?
18
- [].any?
19
- [].many?
20
- Base64
21
- Base64.new
22
- Smtp
23
- Smtp.new
24
- Time.monday?
25
- Time.tuesday?
26
- Time.wednesday?
27
- Time.thursday?
28
- Time.friday?
29
- Time.saturday?
30
- Time.sunday?
31
- Time.now.monday?
32
- Time.now.tuesday?
33
- Time.now.wednesday?
34
- Time.now.thursday?
35
- Time.now.friday?
36
- Time.now.saturday?
37
- Time.now.sunday?
38
- Time.now.second
39
- Time.now.seconds
40
- Time.now.minute
41
- Time.now.minutes
42
- Time.now.hour
43
- Time.now.hours
44
- Time.now.day
45
- Time.now.days
46
- Time.now.month
47
- Time.now.months
48
- Time.now.year
49
- Time.now.years
50
- Time.second
51
- Time.seconds
52
- Time.minute
53
- Time.minutes
54
- Time.hour
55
- Time.hours
56
- Time.day
57
- Time.days
58
- Time.month
59
- Time.months
60
- Time.year
61
- Time.years
62
- 1.day.ago
63
- 1.day.from_now
64
- 1.hour.ago
65
- 1.hour.from_now
66
- 2.days.ago
67
- 2.days.from_now
68
- 2.hours.ago
69
- 2.hours.ago.hour
70
- 2.hours.from_now
71
- 2.hours.from_now.hour
72
- Time.hour
73
- Date.hour
74
- Boolean.new
75
- Boolean.new(true)
76
- Boolean.new(false)
77
- Class.new
78
- Class.new(Boolean)
79
- Class.new(Class)
80
- Context.new
81
- Context.new(a:1)
82
- Date.new
83
- Date.new.hour
84
- Date.new("2024-03-05")
85
- Date.new("2024-03-05").hour
86
- Date.today
87
- Date.yesterday
88
- Date.tomorrow
89
- Date.tomorrow.hour
90
- Decimal.new
91
- Decimal.new(0)
92
- Decimal.new(1.2)
93
- Dictionary.new
94
- Dictionary.new(a:1)
95
- Duration.new
96
- Duration.new(1.day)
97
- Duration.new("P1D")
98
- Function.new
99
- Integer.new
100
- Integer.new(0)
101
- Integer.new(1)
102
- Integer.new(1.2)
103
- List.new
104
- List.new([])
105
- List.new([1,2])
106
- Nothing.new
107
- Nothing.new(1)
108
- Object.new
109
- Object.new(1)
110
- Range.new
111
- Range.new(1,2)
112
- Range.new(-1)
113
- Range.new(1,2,exclude_end:false)
114
- Range.new(1,2,exclude_end:true)
115
- String.new
116
- String.new(:hello)
117
- Time.new
118
- Time.new("2024-03-05.06:10:59.UTC")
119
- Time.now
120
- Time.tomorrow
121
- Time.yesterday
122
- Time.tomorrow
123
- Code.new
124
- Parameter.new
125
- IdentifierList.new
126
- IdentifierList.new([])
127
- Time.new(nothing).before?
128
- Html.link_to
129
- Html.link_to('/')
130
- Html.link_to('Home','/')
131
- Json.parse('1')
132
- Json.parse('[]')
133
- Json.parse('{}')
134
- Json.parse('random-string')
135
- {}["".to_string]
136
- ] + ["Time.hour >= 6 and Time.hour <= 23"]
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"]
137
146
  ).each { |input| it(input) { described_class.evaluate(input) } }
138
147
 
139
148
  [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.6
4
+ version: 1.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié