code-ruby 1.2.2 → 1.2.3

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: 1aa07641fb5e7daf2c529f4ec5abb083d9401de81e49b1f18b01124cab01d82e
4
- data.tar.gz: 7e40438c2b564a9f6e97f334a32509759fdfae25f6b81930431ba6ff0297ade3
3
+ metadata.gz: f7e9396ebb09849d887bc18eb7069427616992d307fa3a556aa24fb330c4c8bf
4
+ data.tar.gz: b97e8a8c3bacbbed9dd14f5b3de85b11a20db9e66e1974e3bfdb1b2e543227a4
5
5
  SHA512:
6
- metadata.gz: f3cb329cbc9ec183c8c15e9cc07256411a56d4b10af3219c2fceb1b55e2ec64c5ad31248f46a4e7a52c374b1cf1e3f68193e12ae15d45a06bf27ba396d4b013a
7
- data.tar.gz: 7953bf969f8f53321260ad044936e2d02f864f1c65361cd87da81d573d7c91ff2c5ebacb6435fb33de134322ed94aaefed23fc0111280cbcfdacf7c8c96516d4
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.2)
4
+ code-ruby (1.2.3)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.2
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
@@ -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,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.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié