code-ruby 1.2.1 → 1.2.3

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: 3e76cc8afa937c6f3e48a31d58fc1b6e9b15aacaea6781fe80426cc081a22df7
4
- data.tar.gz: f49f9bd9d36deb5b9d827b07ce0aa828ef348cd0d86a4f88d3d06c052be280ca
3
+ metadata.gz: f7e9396ebb09849d887bc18eb7069427616992d307fa3a556aa24fb330c4c8bf
4
+ data.tar.gz: b97e8a8c3bacbbed9dd14f5b3de85b11a20db9e66e1974e3bfdb1b2e543227a4
5
5
  SHA512:
6
- metadata.gz: 4719bc78b263558b72bb9071de558cc632e6fc52723029c9d24975ffcf2262e8264dbce9038b6442aa060e1c4b8851bc4fae3f488ee5748113a0ae081d2dbde4
7
- data.tar.gz: 49ed1a4e9423d54f3a8c38d4dc32a93a7807638acd87f4be4a71a2ba2ac7f53cf5c44b40647b85cbff34e222a8867e578cf751bbf9a981325cbb3a00e47c2886
6
+ metadata.gz: 0c3e38a8a8eaeca2aa543c8128ad083a62f2b93a6b7d32efaf9efbb02a315df957b3ae6516031ec22edc573c3fccc3cd4347ffc582ab4083410b01a1ab2bf117
7
+ data.tar.gz: 21ad77b0775d8342799f5fbad810fc52e96b4c3d4bfc25154d614afc6fbd8c1561f1ac85cc4be5adf65e96337bb255585ea8449e5dcd6957318ea171f2b9b739
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.2.1)
4
+ code-ruby (1.2.3)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.3
@@ -22,6 +22,9 @@ class Code
22
22
  when "today"
23
23
  sig(args)
24
24
  code_today
25
+ when "current"
26
+ sig(args)
27
+ code_current
25
28
  when "now"
26
29
  sig(args)
27
30
  code_now
@@ -47,6 +50,11 @@ class Code
47
50
  new(::Time.zone.now.beginning_of_day)
48
51
  end
49
52
 
53
+ def self.code_current
54
+ ::Time.zone ||= Time::DEFAULT_ZONE
55
+ new(::Time.zone.now.beginning_of_day)
56
+ end
57
+
50
58
  def self.code_tomorrow
51
59
  ::Time.zone ||= Time::DEFAULT_ZONE
52
60
  new(::Time.zone.tomorrow.beginning_of_day)
@@ -59,6 +67,8 @@ class Code
59
67
 
60
68
  def call(**args)
61
69
  code_operator = args.fetch(:operator, nil).to_code
70
+ code_arguments = args.fetch(:arguments, []).to_code
71
+ code_value = code_arguments.code_first
62
72
 
63
73
  case code_operator.to_s
64
74
  when "hour"
@@ -79,6 +89,24 @@ class Code
79
89
  when "seconds"
80
90
  sig(args)
81
91
  code_seconds
92
+ when "change"
93
+ sig(args) do
94
+ {
95
+ year: (String | Integer).maybe,
96
+ month: (String | Integer).maybe,
97
+ day: (String | Integer).maybe,
98
+ }
99
+ end
100
+
101
+ if code_value.nothing?
102
+ code_change
103
+ else
104
+ code_change(
105
+ year: code_value.code_get(:year),
106
+ month: code_value.code_get(:month),
107
+ day: code_value.code_get(:day),
108
+ )
109
+ end
82
110
  else
83
111
  super
84
112
  end
@@ -107,6 +135,20 @@ class Code
107
135
  def code_seconds
108
136
  Integer.new(0)
109
137
  end
138
+
139
+ def code_change(year: nil, month: nil, day: nil)
140
+ code_year = year.to_code
141
+ code_month = month.to_code
142
+ code_day = day.to_code
143
+
144
+ raw.change(**{
145
+ year: code_year.raw,
146
+ month: code_month.raw,
147
+ day: code_day.raw
148
+ }.compact)
149
+
150
+ self
151
+ end
110
152
  end
111
153
  end
112
154
  end
@@ -11,7 +11,7 @@ class Code
11
11
  body: String.maybe,
12
12
  username: String.maybe,
13
13
  password: String.maybe,
14
- data: Dictionary.maybe,
14
+ data: Dictionary.maybe
15
15
  }
16
16
  ].freeze
17
17
 
@@ -175,8 +175,9 @@ class Code
175
175
  http.use_ssl = true if uri.scheme == "https"
176
176
 
177
177
  if username.present? || password.present?
178
- headers["Authorization"] =
179
- "Basic #{::Base64.strict_encode64("#{username}:#{password}")}"
178
+ headers[
179
+ "Authorization"
180
+ ] = "Basic #{::Base64.strict_encode64("#{username}:#{password}")}"
180
181
  end
181
182
 
182
183
  request_class =
@@ -42,6 +42,9 @@ class Code
42
42
  when "first"
43
43
  sig(args) { Integer.maybe }
44
44
  code_first(code_value)
45
+ when "sample"
46
+ sig(args) { Integer.maybe }
47
+ code_sample(code_value)
45
48
  when "flatten"
46
49
  sig(args) { Integer.maybe }
47
50
  code_flatten
@@ -167,6 +170,16 @@ class Code
167
170
  end
168
171
  end
169
172
 
173
+ def code_sample(value = nil)
174
+ code_value = value.to_code
175
+
176
+ if code_value.nothing?
177
+ raw.sample || Nothing.new
178
+ else
179
+ List.new(raw.sample(code_value.raw))
180
+ end
181
+ end
182
+
170
183
  def code_flatten(level = nil)
171
184
  code_level = level.to_code
172
185
  code_level = Integer.new(-1) if code_level.nothing?
@@ -7,10 +7,6 @@ class Code
7
7
  UnaryMinus
8
8
  end
9
9
 
10
- def square_bracket
11
- SquareBracket
12
- end
13
-
14
10
  def whitespace
15
11
  Whitespace
16
12
  end
@@ -30,8 +26,8 @@ class Code
30
26
  def root
31
27
  (
32
28
  statement.aka(:left) << (
33
- left_square_bracket << whitespace? << square_bracket <<
34
- (whitespace? << right_square_bracket).maybe
29
+ left_square_bracket << whitespace? << Statement <<
30
+ (whitespace? << right_square_bracket).maybe
35
31
  ).repeat(1).aka(:statements).maybe
36
32
  )
37
33
  .aka(:square_bracket)
data/spec/code_spec.rb CHANGED
@@ -78,6 +78,7 @@ RSpec.describe Code do
78
78
  Json.parse('[]')
79
79
  Json.parse('{}')
80
80
  Json.parse('random-string')
81
+ {}["".to_string]
81
82
  ] + ["Time.hour >= 6 and Time.hour <= 23"]
82
83
  ).each { |input| it(input) { described_class.evaluate(input) } }
83
84
 
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
10
  date: 2025-01-03 00:00:00.000000000 Z
@@ -315,7 +314,6 @@ licenses:
315
314
  - MIT
316
315
  metadata:
317
316
  rubygems_mfa_required: 'true'
318
- post_install_message:
319
317
  rdoc_options: []
320
318
  require_paths:
321
319
  - lib
@@ -330,8 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
328
  - !ruby/object:Gem::Version
331
329
  version: '0'
332
330
  requirements: []
333
- rubygems_version: 3.5.16
334
- signing_key:
331
+ rubygems_version: 3.6.2
335
332
  specification_version: 4
336
333
  summary: a programming language for the internet
337
334
  test_files: []