code-ruby 1.2.4 → 1.2.5
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/html.rb +10 -9
- data/lib/code/object/list.rb +14 -22
- data/lib/code/object/time.rb +77 -0
- data/lib/code-ruby.rb +7 -3
- data/spec/code_spec.rb +12 -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: dc5cea2598154d67fcc651c39a7bfeee5b573fa52aadc4d5f975534c578ef887
|
4
|
+
data.tar.gz: 5f22af50a64fba0be71573c48a5e3bcec67a75de558c239062646d6c640737c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b20becc62e2a60a82913b8a3d9d19132c0ec9df971fe294b716646da21b3b51578536234d365b18d67cb7692f9743067091c99daaff5493804cdb676d6eea97
|
7
|
+
data.tar.gz: c18685983db2eb1995ded8f30161ead10e941d43fd164a8e13b0c45afd09d9d8cf41a53e3f41b9d994ac957c190666dbe37444dcdd45d64621f662463c640701
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.5
|
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/list.rb
CHANGED
@@ -115,17 +115,15 @@ 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
120
|
code_argument.call(
|
121
121
|
arguments: List.new([code_element, Integer.new(index), self]),
|
122
122
|
**globals
|
123
|
-
).truthy
|
123
|
+
).truthy?.tap { index += 1 }
|
124
124
|
end
|
125
125
|
rescue Error::Next => e
|
126
|
-
e.code_value
|
127
|
-
ensure
|
128
|
-
index += 1
|
126
|
+
e.code_value.tap { index += 1 }
|
129
127
|
end
|
130
128
|
)
|
131
129
|
end
|
@@ -271,17 +269,15 @@ class Code
|
|
271
269
|
Boolean.new(
|
272
270
|
raw.none? do |code_element|
|
273
271
|
if code_argument.nothing?
|
274
|
-
code_element.truthy
|
272
|
+
code_element.truthy?.tap { index += 1 }
|
275
273
|
else
|
276
274
|
code_argument.call(
|
277
275
|
arguments: List.new([code_element, Integer.new(index), self]),
|
278
276
|
**globals
|
279
|
-
).truthy
|
277
|
+
).truthy?.tap { index += 1 }
|
280
278
|
end
|
281
279
|
rescue Error::Next => e
|
282
|
-
e.code_value.truthy
|
283
|
-
ensure
|
284
|
-
index += 1
|
280
|
+
e.code_value.truthy?.tap { index += 1 }
|
285
281
|
end
|
286
282
|
)
|
287
283
|
end
|
@@ -310,19 +306,17 @@ class Code
|
|
310
306
|
index = 0
|
311
307
|
|
312
308
|
List.new(
|
313
|
-
raw.
|
309
|
+
raw.select do |code_element|
|
314
310
|
if code_argument.nothing?
|
315
|
-
code_element.
|
311
|
+
code_element.truthy?.tap { index += 1 }
|
316
312
|
else
|
317
313
|
code_argument.call(
|
318
314
|
arguments: List.new([code_element, Integer.new(index), self]),
|
319
315
|
**globals
|
320
|
-
).
|
316
|
+
).truthy?.tap { index += 1 }
|
321
317
|
end
|
322
318
|
rescue Error::Next => e
|
323
|
-
e.code_value.
|
324
|
-
ensure
|
325
|
-
index += 1
|
319
|
+
e.code_value.truhty?.tap { index += 1 }
|
326
320
|
end
|
327
321
|
)
|
328
322
|
end
|
@@ -332,19 +326,17 @@ class Code
|
|
332
326
|
|
333
327
|
index = 0
|
334
328
|
|
335
|
-
raw.
|
329
|
+
raw.select! do |code_element|
|
336
330
|
if code_argument.nothing?
|
337
|
-
code_element.
|
331
|
+
code_element.truthy?.tap { index += 1 }
|
338
332
|
else
|
339
333
|
code_argument.call(
|
340
334
|
arguments: List.new([code_element, Integer.new(index), self]),
|
341
335
|
**globals
|
342
|
-
).
|
336
|
+
).truthy?.tap { index += 1 }
|
343
337
|
end
|
344
338
|
rescue Error::Next => e
|
345
|
-
e.code_value.
|
346
|
-
ensure
|
347
|
-
index += 1
|
339
|
+
e.code_value.truhty?.tap { index += 1 }
|
348
340
|
end
|
349
341
|
|
350
342
|
self
|
data/lib/code/object/time.rb
CHANGED
@@ -68,9 +68,42 @@ class Code
|
|
68
68
|
when "future?"
|
69
69
|
sig(args)
|
70
70
|
code_future?
|
71
|
+
when "year"
|
72
|
+
sig(args)
|
73
|
+
code_year
|
74
|
+
when "years"
|
75
|
+
sig(args)
|
76
|
+
code_years
|
77
|
+
when "month"
|
78
|
+
sig(args)
|
79
|
+
code_month
|
80
|
+
when "months"
|
81
|
+
sig(args)
|
82
|
+
code_months
|
83
|
+
when "day"
|
84
|
+
sig(args)
|
85
|
+
code_day
|
86
|
+
when "days"
|
87
|
+
sig(args)
|
88
|
+
code_days
|
71
89
|
when "hour"
|
72
90
|
sig(args)
|
73
91
|
code_hour
|
92
|
+
when "hours"
|
93
|
+
sig(args)
|
94
|
+
code_hours
|
95
|
+
when "minute"
|
96
|
+
sig(args)
|
97
|
+
code_minute
|
98
|
+
when "minutes"
|
99
|
+
sig(args)
|
100
|
+
code_minutes
|
101
|
+
when "second"
|
102
|
+
sig(args)
|
103
|
+
code_second
|
104
|
+
when "seconds"
|
105
|
+
sig(args)
|
106
|
+
code_seconds
|
74
107
|
when "format"
|
75
108
|
sig(args) { String }
|
76
109
|
code_format(code_value)
|
@@ -101,10 +134,54 @@ class Code
|
|
101
134
|
code_after?
|
102
135
|
end
|
103
136
|
|
137
|
+
def code_year
|
138
|
+
Integer.new(raw.year)
|
139
|
+
end
|
140
|
+
|
141
|
+
def code_years
|
142
|
+
Integer.new(raw.year)
|
143
|
+
end
|
144
|
+
|
145
|
+
def code_month
|
146
|
+
Integer.new(raw.month)
|
147
|
+
end
|
148
|
+
|
149
|
+
def code_months
|
150
|
+
Integer.new(raw.month)
|
151
|
+
end
|
152
|
+
|
153
|
+
def code_day
|
154
|
+
Integer.new(raw.day)
|
155
|
+
end
|
156
|
+
|
157
|
+
def code_days
|
158
|
+
Integer.new(raw.day)
|
159
|
+
end
|
160
|
+
|
104
161
|
def code_hour
|
105
162
|
Integer.new(raw.hour)
|
106
163
|
end
|
107
164
|
|
165
|
+
def code_hours
|
166
|
+
Integer.new(raw.hour)
|
167
|
+
end
|
168
|
+
|
169
|
+
def code_minute
|
170
|
+
Integer.new(raw.min)
|
171
|
+
end
|
172
|
+
|
173
|
+
def code_minutes
|
174
|
+
Integer.new(raw.min)
|
175
|
+
end
|
176
|
+
|
177
|
+
def code_second
|
178
|
+
Integer.new(raw.sec)
|
179
|
+
end
|
180
|
+
|
181
|
+
def code_seconds
|
182
|
+
Integer.new(raw.sec)
|
183
|
+
end
|
184
|
+
|
108
185
|
def code_format(format)
|
109
186
|
code_format = format.to_code
|
110
187
|
|
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,18 @@ 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
|
8
20
|
1.day.ago
|
9
21
|
1.day.from_now
|
10
22
|
1.hour.ago
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|