code-ruby 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -1
- data/VERSION +1 -1
- data/code-ruby.gemspec +1 -0
- data/lib/code/object/date.rb +9 -7
- data/lib/code/object/dictionary.rb +1 -1
- data/lib/code/object/html.rb +58 -0
- data/lib/code/object/list.rb +52 -0
- data/lib/code/object/string.rb +9 -0
- data/lib/code/object/time.rb +9 -0
- data/lib/code/parser/square_bracket.rb +1 -1
- data/lib/code-ruby.rb +7 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90f22080323e543a0af569f126910e440deafe34ae8c8e44684a22cb5c4e6339
|
4
|
+
data.tar.gz: 5bd9cb88112781491172e9239aea326dbd92c0b5dc2d42b7b2aebb2cc5fb1cdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e5f00fad4846b46233f20b9ef29c21af07bdd7dec262b68cdf19bd60e143624f1d6336ba4d0e09ed71661f1ad8a48f57b4d2857ad4a29904369b9d7f376d600
|
7
|
+
data.tar.gz: b0b61d5324f112a5a19d8a981bbfe91ce5c77be30a1b246b7143e62b7585d0cfbc4baa8665f32c8c579520ddfc29208d43169414ef2463f8c6516f8b03cdc937
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code-ruby (1.2.
|
4
|
+
code-ruby (1.2.4)
|
5
5
|
activesupport
|
6
6
|
base64
|
7
7
|
bigdecimal
|
@@ -10,6 +10,7 @@ PATH
|
|
10
10
|
json
|
11
11
|
language-ruby
|
12
12
|
net-http
|
13
|
+
nokogiri
|
13
14
|
uri
|
14
15
|
zeitwerk
|
15
16
|
|
@@ -101,6 +102,7 @@ GEM
|
|
101
102
|
libv8-node (18.19.0.0-arm64-darwin)
|
102
103
|
libv8-node (18.19.0.0-x86_64-linux)
|
103
104
|
logger (1.6.4)
|
105
|
+
mini_portile2 (2.8.8)
|
104
106
|
mini_racer (0.16.0)
|
105
107
|
libv8-node (~> 18.19.0.0)
|
106
108
|
minitest (5.25.4)
|
@@ -108,6 +110,13 @@ GEM
|
|
108
110
|
ruby2_keywords (~> 0.0.1)
|
109
111
|
net-http (0.6.0)
|
110
112
|
uri
|
113
|
+
nokogiri (1.18.1)
|
114
|
+
mini_portile2 (~> 2.8.2)
|
115
|
+
racc (~> 1.4)
|
116
|
+
nokogiri (1.18.1-arm64-darwin)
|
117
|
+
racc (~> 1.4)
|
118
|
+
nokogiri (1.18.1-x86_64-linux-gnu)
|
119
|
+
racc (~> 1.4)
|
111
120
|
openssl (3.2.1)
|
112
121
|
ostruct (0.6.1)
|
113
122
|
parallel (1.26.3)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.4
|
data/code-ruby.gemspec
CHANGED
data/lib/code/object/date.rb
CHANGED
@@ -94,7 +94,7 @@ class Code
|
|
94
94
|
{
|
95
95
|
year: (String | Integer).maybe,
|
96
96
|
month: (String | Integer).maybe,
|
97
|
-
day: (String | Integer).maybe
|
97
|
+
day: (String | Integer).maybe
|
98
98
|
}
|
99
99
|
end
|
100
100
|
|
@@ -104,7 +104,7 @@ class Code
|
|
104
104
|
code_change(
|
105
105
|
year: code_value.code_get(:year),
|
106
106
|
month: code_value.code_get(:month),
|
107
|
-
day: code_value.code_get(:day)
|
107
|
+
day: code_value.code_get(:day)
|
108
108
|
)
|
109
109
|
end
|
110
110
|
else
|
@@ -141,11 +141,13 @@ class Code
|
|
141
141
|
code_month = month.to_code
|
142
142
|
code_day = day.to_code
|
143
143
|
|
144
|
-
raw.change(
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
raw.change(
|
145
|
+
**{
|
146
|
+
year: code_year.raw,
|
147
|
+
month: code_month.raw,
|
148
|
+
day: code_day.raw
|
149
|
+
}.compact
|
150
|
+
)
|
149
151
|
|
150
152
|
self
|
151
153
|
end
|
data/lib/code/object/html.rb
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
class Code
|
4
4
|
class Object
|
5
5
|
class Html < Object
|
6
|
+
def initialize(*args, **_kargs, &)
|
7
|
+
if args.first.is_an?(Html)
|
8
|
+
@raw = args.first.raw
|
9
|
+
elsif args.first.is_a?(::Nokogiri::XML::NodeSet)
|
10
|
+
@raw = args.first
|
11
|
+
elsif args.first.is_a?(Nokogiri::XML::Node)
|
12
|
+
@raw = args.first
|
13
|
+
else
|
14
|
+
@raw = Nokogiri::HTML(args.first.to_s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
def self.call(**args)
|
7
19
|
code_operator = args.fetch(:operator, nil).to_code
|
8
20
|
code_arguments = args.fetch(:arguments, []).to_code
|
@@ -35,6 +47,52 @@ class Code
|
|
35
47
|
|
36
48
|
String.new(CGI.escapeHTML(string.to_s))
|
37
49
|
end
|
50
|
+
|
51
|
+
def call(**args)
|
52
|
+
code_operator = args.fetch(:operator, nil).to_code
|
53
|
+
code_arguments = args.fetch(:arguments, []).to_code
|
54
|
+
code_value = code_arguments.code_first
|
55
|
+
globals = multi_fetch(args, *GLOBALS)
|
56
|
+
|
57
|
+
case code_operator.to_s
|
58
|
+
when "css"
|
59
|
+
sig(args) { String }
|
60
|
+
code_css(code_value)
|
61
|
+
when "map"
|
62
|
+
sig(args) { Function }
|
63
|
+
code_map(code_value, **globals)
|
64
|
+
when "to_string"
|
65
|
+
sig(args)
|
66
|
+
code_to_string
|
67
|
+
else
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def code_css(query)
|
73
|
+
code_query = query.to_code
|
74
|
+
|
75
|
+
Html.new(raw.css(code_query.raw))
|
76
|
+
end
|
77
|
+
|
78
|
+
def code_map(argument, **globals)
|
79
|
+
code_argument = argument.to_code
|
80
|
+
|
81
|
+
List.new(
|
82
|
+
raw.map.with_index do |element, index|
|
83
|
+
code_argument.call(
|
84
|
+
arguments: List.new([element.to_code, Integer.new(index), self]),
|
85
|
+
**globals
|
86
|
+
)
|
87
|
+
rescue Error::Next => e
|
88
|
+
e.code_value
|
89
|
+
end
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
def code_to_string
|
94
|
+
String.new(raw.text)
|
95
|
+
end
|
38
96
|
end
|
39
97
|
end
|
40
98
|
end
|
data/lib/code/object/list.rb
CHANGED
@@ -81,6 +81,12 @@ class Code
|
|
81
81
|
when "select!"
|
82
82
|
sig(args) { Function }
|
83
83
|
code_select!(code_value, **globals)
|
84
|
+
when "compact"
|
85
|
+
sig(args) { Function.maybe }
|
86
|
+
code_compact(code_value, **globals)
|
87
|
+
when "compact!"
|
88
|
+
sig(args) { Function.maybe }
|
89
|
+
code_compact!(code_value, **globals)
|
84
90
|
when "reject"
|
85
91
|
sig(args) { Function }
|
86
92
|
code_reject(code_value, **globals)
|
@@ -298,6 +304,52 @@ class Code
|
|
298
304
|
List.new(raw.reverse)
|
299
305
|
end
|
300
306
|
|
307
|
+
def code_compact(argument = nil, **globals)
|
308
|
+
code_argument = argument.to_code
|
309
|
+
|
310
|
+
index = 0
|
311
|
+
|
312
|
+
List.new(
|
313
|
+
raw.compact do |code_element|
|
314
|
+
if code_argument.nothing?
|
315
|
+
code_element.falsy?
|
316
|
+
else
|
317
|
+
code_argument.call(
|
318
|
+
arguments: List.new([code_element, Integer.new(index), self]),
|
319
|
+
**globals
|
320
|
+
).falsy?
|
321
|
+
end
|
322
|
+
rescue Error::Next => e
|
323
|
+
e.code_value.falsy?
|
324
|
+
ensure
|
325
|
+
index += 1
|
326
|
+
end
|
327
|
+
)
|
328
|
+
end
|
329
|
+
|
330
|
+
def code_compact!(argument = nil, **globals)
|
331
|
+
code_argument = argument.to_code
|
332
|
+
|
333
|
+
index = 0
|
334
|
+
|
335
|
+
raw.compact! do |code_element|
|
336
|
+
if code_argument.nothing?
|
337
|
+
code_element.falsy?
|
338
|
+
else
|
339
|
+
code_argument.call(
|
340
|
+
arguments: List.new([code_element, Integer.new(index), self]),
|
341
|
+
**globals
|
342
|
+
).falsy?
|
343
|
+
end
|
344
|
+
rescue Error::Next => e
|
345
|
+
e.code_value.falsy?
|
346
|
+
ensure
|
347
|
+
index += 1
|
348
|
+
end
|
349
|
+
|
350
|
+
self
|
351
|
+
end
|
352
|
+
|
301
353
|
def code_select(argument, **globals)
|
302
354
|
code_argument = argument.to_code
|
303
355
|
|
data/lib/code/object/string.rb
CHANGED
@@ -31,6 +31,9 @@ class Code
|
|
31
31
|
when "include?"
|
32
32
|
sig(args) { String }
|
33
33
|
code_include?(code_value)
|
34
|
+
when "first"
|
35
|
+
sig(args) { Integer.maybe }
|
36
|
+
code_first(code_value)
|
34
37
|
when "reverse"
|
35
38
|
sig(args)
|
36
39
|
code_reverse
|
@@ -65,6 +68,12 @@ class Code
|
|
65
68
|
def code_to_function(**_globals)
|
66
69
|
Function.new([{ name: "_" }], "_.#{raw}")
|
67
70
|
end
|
71
|
+
|
72
|
+
def code_first(n = nil)
|
73
|
+
code_n = n.to_code
|
74
|
+
code_n = Integer.new(1) if code_n.nothing?
|
75
|
+
String.new(raw.first(code_n.raw))
|
76
|
+
end
|
68
77
|
end
|
69
78
|
end
|
70
79
|
end
|
data/lib/code/object/time.rb
CHANGED
@@ -71,6 +71,9 @@ class Code
|
|
71
71
|
when "hour"
|
72
72
|
sig(args)
|
73
73
|
code_hour
|
74
|
+
when "format"
|
75
|
+
sig(args) { String }
|
76
|
+
code_format(code_value)
|
74
77
|
else
|
75
78
|
super
|
76
79
|
end
|
@@ -101,6 +104,12 @@ class Code
|
|
101
104
|
def code_hour
|
102
105
|
Integer.new(raw.hour)
|
103
106
|
end
|
107
|
+
|
108
|
+
def code_format(format)
|
109
|
+
code_format = format.to_code
|
110
|
+
|
111
|
+
String.new(raw.strftime(code_format.raw))
|
112
|
+
end
|
104
113
|
end
|
105
114
|
end
|
106
115
|
end
|
@@ -27,7 +27,7 @@ class Code
|
|
27
27
|
(
|
28
28
|
statement.aka(:left) << (
|
29
29
|
left_square_bracket << whitespace? << Statement <<
|
30
|
-
|
30
|
+
(whitespace? << right_square_bracket).maybe
|
31
31
|
).repeat(1).aka(:statements).maybe
|
32
32
|
)
|
33
33
|
.aka(:square_bracket)
|
data/lib/code-ruby.rb
CHANGED
@@ -8,6 +8,7 @@ require "did_you_mean"
|
|
8
8
|
require "json"
|
9
9
|
require "language-ruby"
|
10
10
|
require "net/http"
|
11
|
+
require "nokogiri"
|
11
12
|
require "stringio"
|
12
13
|
require "timeout"
|
13
14
|
require "uri"
|
@@ -136,3 +137,9 @@ class Hash
|
|
136
137
|
Code::Object::Dictionary.new(self)
|
137
138
|
end
|
138
139
|
end
|
140
|
+
|
141
|
+
class Nokogiri::XML::Element
|
142
|
+
def to_code
|
143
|
+
Code::Object::Html.new(self)
|
144
|
+
end
|
145
|
+
end
|
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.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
@@ -121,6 +121,20 @@ dependencies:
|
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: nokogiri
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
type: :runtime
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
124
138
|
- !ruby/object:Gem::Dependency
|
125
139
|
name: uri
|
126
140
|
requirement: !ruby/object:Gem::Requirement
|