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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90f22080323e543a0af569f126910e440deafe34ae8c8e44684a22cb5c4e6339
4
- data.tar.gz: 5bd9cb88112781491172e9239aea326dbd92c0b5dc2d42b7b2aebb2cc5fb1cdc
3
+ metadata.gz: dc5cea2598154d67fcc651c39a7bfeee5b573fa52aadc4d5f975534c578ef887
4
+ data.tar.gz: 5f22af50a64fba0be71573c48a5e3bcec67a75de558c239062646d6c640737c1
5
5
  SHA512:
6
- metadata.gz: 2e5f00fad4846b46233f20b9ef29c21af07bdd7dec262b68cdf19bd60e143624f1d6336ba4d0e09ed71661f1ad8a48f57b4d2857ad4a29904369b9d7f376d600
7
- data.tar.gz: b0b61d5324f112a5a19d8a981bbfe91ce5c77be30a1b246b7143e62b7585d0cfbc4baa8665f32c8c579520ddfc29208d43169414ef2463f8c6516f8b03cdc937
6
+ metadata.gz: 9b20becc62e2a60a82913b8a3d9d19132c0ec9df971fe294b716646da21b3b51578536234d365b18d67cb7692f9743067091c99daaff5493804cdb676d6eea97
7
+ data.tar.gz: c18685983db2eb1995ded8f30161ead10e941d43fd164a8e13b0c45afd09d9d8cf41a53e3f41b9d994ac957c190666dbe37444dcdd45d64621f662463c640701
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.2.4)
4
+ code-ruby (1.2.5)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.2.5
@@ -4,15 +4,16 @@ class Code
4
4
  class Object
5
5
  class Html < Object
6
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
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)
@@ -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.compact do |code_element|
309
+ raw.select do |code_element|
314
310
  if code_argument.nothing?
315
- code_element.falsy?
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
- ).falsy?
316
+ ).truthy?.tap { index += 1 }
321
317
  end
322
318
  rescue Error::Next => e
323
- e.code_value.falsy?
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.compact! do |code_element|
329
+ raw.select! do |code_element|
336
330
  if code_argument.nothing?
337
- code_element.falsy?
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
- ).falsy?
336
+ ).truthy?.tap { index += 1 }
343
337
  end
344
338
  rescue Error::Next => e
345
- e.code_value.falsy?
346
- ensure
347
- index += 1
339
+ e.code_value.truhty?.tap { index += 1 }
348
340
  end
349
341
 
350
342
  self
@@ -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
- class Nokogiri::XML::Element
142
- def to_code
143
- Code::Object::Html.new(self)
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
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-03 00:00:00.000000000 Z
10
+ date: 2025-01-04 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport