code-ruby 1.2.4 → 1.2.6
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/node/left_operation.rb +3 -3
- data/lib/code/object/dictionary.rb +9 -0
- data/lib/code/object/html.rb +10 -9
- data/lib/code/object/http.rb +0 -9
- data/lib/code/object/list.rb +38 -34
- data/lib/code/object/time.rb +221 -0
- data/lib/code-ruby.rb +7 -3
- data/spec/code/object/http_spec.rb +1 -1
- data/spec/code_spec.rb +25 -0
- 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: d8f07ece7647c8a08b818c2221a625076d0108018a015c9752c3dd2b40e88a0b
|
4
|
+
data.tar.gz: 288fe4424fe0739514fc34479ecf1292b6e0277369e1b4e1bdf00445eebd18c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aec2589dc56ae830a82d36dd3f9005427d9ac3008381397a7b876187d990ffceb00b69a0c781a39871da3c6ffcaf53ece8749633c24b18cddf1f6993bbb79f1e
|
7
|
+
data.tar.gz: 26ac7c6070382e493c9b879807eb11962ccdd579a4ad054bacc039dda8d0e66ee05beaad14d36f192d2c41119032eda75992830a184804c8effcbd54b6bdf0eb
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.6
|
@@ -22,7 +22,7 @@ class Code
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def call?
|
25
|
-
|
25
|
+
[DOT, COLON_COLON].include?(operator)
|
26
26
|
end
|
27
27
|
|
28
28
|
def safe_call?
|
@@ -30,11 +30,11 @@ class Code
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def or?
|
33
|
-
|
33
|
+
[OR_KEYWORD, PIPE_PIPE].include?(operator)
|
34
34
|
end
|
35
35
|
|
36
36
|
def and?
|
37
|
-
|
37
|
+
[AND_KEYWORD, AMPERSAND_AMPERSAND].include?(operator)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -169,6 +169,9 @@ class Code
|
|
169
169
|
when "transform_values"
|
170
170
|
sig(args) { Function }
|
171
171
|
code_transform_values(code_value, **globals)
|
172
|
+
when "to_query"
|
173
|
+
sig(args) { String.maybe }
|
174
|
+
code_to_query(code_value)
|
172
175
|
when "two?"
|
173
176
|
sig(args)
|
174
177
|
code_two?
|
@@ -632,6 +635,12 @@ class Code
|
|
632
635
|
List.new(raw.to_a.map { |key_value| List.new(key_value) })
|
633
636
|
end
|
634
637
|
|
638
|
+
def code_to_query(namespace = nil)
|
639
|
+
code_namespace = namespace.to_code
|
640
|
+
|
641
|
+
String.new(raw.to_query(code_namespace.raw))
|
642
|
+
end
|
643
|
+
|
635
644
|
def code_transform_values(function, **globals)
|
636
645
|
code_function = function.to_code
|
637
646
|
|
data/lib/code/object/html.rb
CHANGED
@@ -4,15 +4,16 @@ class Code
|
|
4
4
|
class Object
|
5
5
|
class Html < Object
|
6
6
|
def initialize(*args, **_kargs, &)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
@raw =
|
8
|
+
if args.first.is_an?(Html)
|
9
|
+
args.first.raw
|
10
|
+
elsif args.first.is_a?(::Nokogiri::XML::NodeSet)
|
11
|
+
args.first
|
12
|
+
elsif args.first.is_a?(Nokogiri::XML::Node)
|
13
|
+
args.first
|
14
|
+
else
|
15
|
+
Nokogiri.HTML(args.first.to_s)
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.call(**args)
|
data/lib/code/object/http.rb
CHANGED
@@ -101,9 +101,6 @@ class Code
|
|
101
101
|
when "delete"
|
102
102
|
sig(args) { SIG }
|
103
103
|
code_delete(*code_arguments.raw)
|
104
|
-
when "connect"
|
105
|
-
sig(args) { SIG }
|
106
|
-
code_connect(*code_arguments.raw)
|
107
104
|
when "options"
|
108
105
|
sig(args) { SIG }
|
109
106
|
code_options(*code_arguments.raw)
|
@@ -141,10 +138,6 @@ class Code
|
|
141
138
|
code_fetch("delete", ...)
|
142
139
|
end
|
143
140
|
|
144
|
-
def self.code_connect(...)
|
145
|
-
code_fetch("connect", ...)
|
146
|
-
end
|
147
|
-
|
148
141
|
def self.code_options(...)
|
149
142
|
code_fetch("options", ...)
|
150
143
|
end
|
@@ -192,8 +185,6 @@ class Code
|
|
192
185
|
::Net::HTTP::Put
|
193
186
|
when "delete"
|
194
187
|
::Net::HTTP::Delete
|
195
|
-
when "connect"
|
196
|
-
::Net::HTTP::Get
|
197
188
|
when "options"
|
198
189
|
::Net::HTTP::Options
|
199
190
|
when "trace"
|
data/lib/code/object/list.rb
CHANGED
@@ -115,17 +115,18 @@ class Code
|
|
115
115
|
Boolean.new(
|
116
116
|
raw.any? do |code_element|
|
117
117
|
if code_argument.nothing?
|
118
|
-
true
|
118
|
+
true.tap { index += 1 }
|
119
119
|
else
|
120
|
-
code_argument
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
code_argument
|
121
|
+
.call(
|
122
|
+
arguments: List.new([code_element, Integer.new(index), self]),
|
123
|
+
**globals
|
124
|
+
)
|
125
|
+
.truthy?
|
126
|
+
.tap { index += 1 }
|
124
127
|
end
|
125
128
|
rescue Error::Next => e
|
126
|
-
e.code_value
|
127
|
-
ensure
|
128
|
-
index += 1
|
129
|
+
e.code_value.tap { index += 1 }
|
129
130
|
end
|
130
131
|
)
|
131
132
|
end
|
@@ -271,17 +272,18 @@ class Code
|
|
271
272
|
Boolean.new(
|
272
273
|
raw.none? do |code_element|
|
273
274
|
if code_argument.nothing?
|
274
|
-
code_element.truthy
|
275
|
+
code_element.truthy?.tap { index += 1 }
|
275
276
|
else
|
276
|
-
code_argument
|
277
|
-
|
278
|
-
|
279
|
-
|
277
|
+
code_argument
|
278
|
+
.call(
|
279
|
+
arguments: List.new([code_element, Integer.new(index), self]),
|
280
|
+
**globals
|
281
|
+
)
|
282
|
+
.truthy?
|
283
|
+
.tap { index += 1 }
|
280
284
|
end
|
281
285
|
rescue Error::Next => e
|
282
|
-
e.code_value.truthy
|
283
|
-
ensure
|
284
|
-
index += 1
|
286
|
+
e.code_value.truthy?.tap { index += 1 }
|
285
287
|
end
|
286
288
|
)
|
287
289
|
end
|
@@ -310,19 +312,20 @@ class Code
|
|
310
312
|
index = 0
|
311
313
|
|
312
314
|
List.new(
|
313
|
-
raw.
|
315
|
+
raw.select do |code_element|
|
314
316
|
if code_argument.nothing?
|
315
|
-
code_element.
|
317
|
+
code_element.truthy?.tap { index += 1 }
|
316
318
|
else
|
317
|
-
code_argument
|
318
|
-
|
319
|
-
|
320
|
-
|
319
|
+
code_argument
|
320
|
+
.call(
|
321
|
+
arguments: List.new([code_element, Integer.new(index), self]),
|
322
|
+
**globals
|
323
|
+
)
|
324
|
+
.truthy?
|
325
|
+
.tap { index += 1 }
|
321
326
|
end
|
322
327
|
rescue Error::Next => e
|
323
|
-
e.code_value.
|
324
|
-
ensure
|
325
|
-
index += 1
|
328
|
+
e.code_value.truhty?.tap { index += 1 }
|
326
329
|
end
|
327
330
|
)
|
328
331
|
end
|
@@ -332,19 +335,20 @@ class Code
|
|
332
335
|
|
333
336
|
index = 0
|
334
337
|
|
335
|
-
raw.
|
338
|
+
raw.select! do |code_element|
|
336
339
|
if code_argument.nothing?
|
337
|
-
code_element.
|
340
|
+
code_element.truthy?.tap { index += 1 }
|
338
341
|
else
|
339
|
-
code_argument
|
340
|
-
|
341
|
-
|
342
|
-
|
342
|
+
code_argument
|
343
|
+
.call(
|
344
|
+
arguments: List.new([code_element, Integer.new(index), self]),
|
345
|
+
**globals
|
346
|
+
)
|
347
|
+
.truthy?
|
348
|
+
.tap { index += 1 }
|
343
349
|
end
|
344
350
|
rescue Error::Next => e
|
345
|
-
e.code_value.
|
346
|
-
ensure
|
347
|
-
index += 1
|
351
|
+
e.code_value.truhty?.tap { index += 1 }
|
348
352
|
end
|
349
353
|
|
350
354
|
self
|
data/lib/code/object/time.rb
CHANGED
@@ -23,9 +23,57 @@ class Code
|
|
23
23
|
when "yesterday"
|
24
24
|
sig(args)
|
25
25
|
code_yesterday
|
26
|
+
when "year"
|
27
|
+
sig(args)
|
28
|
+
code_year
|
29
|
+
when "years"
|
30
|
+
sig(args)
|
31
|
+
code_years
|
32
|
+
when "month"
|
33
|
+
sig(args)
|
34
|
+
code_month
|
35
|
+
when "months"
|
36
|
+
sig(args)
|
37
|
+
code_months
|
38
|
+
when "week"
|
39
|
+
sig(args)
|
40
|
+
code_week
|
41
|
+
when "weeks"
|
42
|
+
sig(args)
|
43
|
+
code_weeks
|
44
|
+
when "week_day"
|
45
|
+
sig(args)
|
46
|
+
code_week_day
|
47
|
+
when "week_days"
|
48
|
+
sig(args)
|
49
|
+
code_week_days
|
50
|
+
when "day"
|
51
|
+
sig(args)
|
52
|
+
code_day
|
53
|
+
when "days"
|
54
|
+
sig(args)
|
55
|
+
code_days
|
26
56
|
when "hour"
|
27
57
|
sig(args)
|
28
58
|
code_hour
|
59
|
+
when "hours"
|
60
|
+
sig(args)
|
61
|
+
code_hours
|
62
|
+
when "minute"
|
63
|
+
sig(args)
|
64
|
+
code_minute
|
65
|
+
when "minutes"
|
66
|
+
sig(args)
|
67
|
+
code_minutes
|
68
|
+
when "second"
|
69
|
+
sig(args)
|
70
|
+
code_second
|
71
|
+
when "seconds"
|
72
|
+
sig(args)
|
73
|
+
code_seconds
|
74
|
+
when "format"
|
75
|
+
sig(args) { String }
|
76
|
+
code_format(code_value)
|
29
77
|
else
|
30
78
|
super
|
31
79
|
end
|
@@ -50,6 +98,74 @@ class Code
|
|
50
98
|
new(::Time.zone.now)
|
51
99
|
end
|
52
100
|
|
101
|
+
def self.code_year
|
102
|
+
code_now.code_year
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.code_years
|
106
|
+
code_now.code_years
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.code_month
|
110
|
+
code_now.code_month
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.code_months
|
114
|
+
code_now.code_months
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.code_week
|
118
|
+
code_now.code_week
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.code_weeks
|
122
|
+
code_now.code_weeks
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.code_week_day
|
126
|
+
code_now.code_week_day
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.code_week_days
|
130
|
+
code_now.code_week_days
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.code_day
|
134
|
+
code_now.code_day
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.code_days
|
138
|
+
code_now.code_days
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.code_hour
|
142
|
+
code_now.code_hour
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.code_hours
|
146
|
+
code_now.code_hours
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.code_minute
|
150
|
+
code_now.code_minute
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.code_minutes
|
154
|
+
code_now.code_minutes
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.code_second
|
158
|
+
code_now.code_second
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.code_seconds
|
162
|
+
code_now.code_seconds
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.code_format(format)
|
166
|
+
code_now.code_format(format)
|
167
|
+
end
|
168
|
+
|
53
169
|
def call(**args)
|
54
170
|
code_operator = args.fetch(:operator, nil).to_code
|
55
171
|
code_arguments = args.fetch(:arguments, []).to_code
|
@@ -68,9 +184,54 @@ class Code
|
|
68
184
|
when "future?"
|
69
185
|
sig(args)
|
70
186
|
code_future?
|
187
|
+
when "year"
|
188
|
+
sig(args)
|
189
|
+
code_year
|
190
|
+
when "years"
|
191
|
+
sig(args)
|
192
|
+
code_years
|
193
|
+
when "month"
|
194
|
+
sig(args)
|
195
|
+
code_month
|
196
|
+
when "months"
|
197
|
+
sig(args)
|
198
|
+
code_months
|
199
|
+
when "week"
|
200
|
+
sig(args)
|
201
|
+
code_week
|
202
|
+
when "weeks"
|
203
|
+
sig(args)
|
204
|
+
code_weeks
|
205
|
+
when "week_day"
|
206
|
+
sig(args)
|
207
|
+
code_week_day
|
208
|
+
when "week_days"
|
209
|
+
sig(args)
|
210
|
+
code_week_days
|
211
|
+
when "day"
|
212
|
+
sig(args)
|
213
|
+
code_day
|
214
|
+
when "days"
|
215
|
+
sig(args)
|
216
|
+
code_days
|
71
217
|
when "hour"
|
72
218
|
sig(args)
|
73
219
|
code_hour
|
220
|
+
when "hours"
|
221
|
+
sig(args)
|
222
|
+
code_hours
|
223
|
+
when "minute"
|
224
|
+
sig(args)
|
225
|
+
code_minute
|
226
|
+
when "minutes"
|
227
|
+
sig(args)
|
228
|
+
code_minutes
|
229
|
+
when "second"
|
230
|
+
sig(args)
|
231
|
+
code_second
|
232
|
+
when "seconds"
|
233
|
+
sig(args)
|
234
|
+
code_seconds
|
74
235
|
when "format"
|
75
236
|
sig(args) { String }
|
76
237
|
code_format(code_value)
|
@@ -101,10 +262,70 @@ class Code
|
|
101
262
|
code_after?
|
102
263
|
end
|
103
264
|
|
265
|
+
def code_year
|
266
|
+
Integer.new(raw.year)
|
267
|
+
end
|
268
|
+
|
269
|
+
def code_years
|
270
|
+
Integer.new(raw.year)
|
271
|
+
end
|
272
|
+
|
273
|
+
def code_month
|
274
|
+
Integer.new(raw.month)
|
275
|
+
end
|
276
|
+
|
277
|
+
def code_months
|
278
|
+
Integer.new(raw.month)
|
279
|
+
end
|
280
|
+
|
281
|
+
def code_week
|
282
|
+
Integer.new(raw.to_date.cweek)
|
283
|
+
end
|
284
|
+
|
285
|
+
def code_weeks
|
286
|
+
Integer.new(raw.to_date.cweek)
|
287
|
+
end
|
288
|
+
|
289
|
+
def code_week_day
|
290
|
+
Integer.new(raw.wday)
|
291
|
+
end
|
292
|
+
|
293
|
+
def code_week_days
|
294
|
+
Integer.new(raw.wday)
|
295
|
+
end
|
296
|
+
|
297
|
+
def code_day
|
298
|
+
Integer.new(raw.day)
|
299
|
+
end
|
300
|
+
|
301
|
+
def code_days
|
302
|
+
Integer.new(raw.day)
|
303
|
+
end
|
304
|
+
|
104
305
|
def code_hour
|
105
306
|
Integer.new(raw.hour)
|
106
307
|
end
|
107
308
|
|
309
|
+
def code_hours
|
310
|
+
Integer.new(raw.hour)
|
311
|
+
end
|
312
|
+
|
313
|
+
def code_minute
|
314
|
+
Integer.new(raw.min)
|
315
|
+
end
|
316
|
+
|
317
|
+
def code_minutes
|
318
|
+
Integer.new(raw.min)
|
319
|
+
end
|
320
|
+
|
321
|
+
def code_second
|
322
|
+
Integer.new(raw.sec)
|
323
|
+
end
|
324
|
+
|
325
|
+
def code_seconds
|
326
|
+
Integer.new(raw.sec)
|
327
|
+
end
|
328
|
+
|
108
329
|
def code_format(format)
|
109
330
|
code_format = format.to_code
|
110
331
|
|
data/lib/code-ruby.rb
CHANGED
@@ -138,8 +138,12 @@ class Hash
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
module Nokogiri
|
142
|
+
module XML
|
143
|
+
class Element
|
144
|
+
def to_code
|
145
|
+
Code::Object::Html.new(self)
|
146
|
+
end
|
147
|
+
end
|
144
148
|
end
|
145
149
|
end
|
data/spec/code_spec.rb
CHANGED
@@ -5,6 +5,30 @@ require "spec_helper"
|
|
5
5
|
RSpec.describe Code do
|
6
6
|
(
|
7
7
|
%w[
|
8
|
+
Time.now.second
|
9
|
+
Time.now.seconds
|
10
|
+
Time.now.minute
|
11
|
+
Time.now.minutes
|
12
|
+
Time.now.hour
|
13
|
+
Time.now.hours
|
14
|
+
Time.now.day
|
15
|
+
Time.now.days
|
16
|
+
Time.now.month
|
17
|
+
Time.now.months
|
18
|
+
Time.now.year
|
19
|
+
Time.now.years
|
20
|
+
Time.second
|
21
|
+
Time.seconds
|
22
|
+
Time.minute
|
23
|
+
Time.minutes
|
24
|
+
Time.hour
|
25
|
+
Time.hours
|
26
|
+
Time.day
|
27
|
+
Time.days
|
28
|
+
Time.month
|
29
|
+
Time.months
|
30
|
+
Time.year
|
31
|
+
Time.years
|
8
32
|
1.day.ago
|
9
33
|
1.day.from_now
|
10
34
|
1.hour.ago
|
@@ -317,6 +341,7 @@ RSpec.describe Code do
|
|
317
341
|
["[1, 2, 3].none?(&:even?)", "false"],
|
318
342
|
["'{1} {2}'", "'1 2'"],
|
319
343
|
%w[Json.parse("1") 1],
|
344
|
+
%w[{a:1}.to_query "a=1"],
|
320
345
|
["", ""]
|
321
346
|
].each do |input, expected|
|
322
347
|
it "#{input} == #{expected}" do
|
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.2.
|
4
|
+
version: 1.2.6
|
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-03-24 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|