code-ruby 1.8.3 → 1.8.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/object/list.rb +35 -4
- data/lib/code/object/time.rb +11 -0
- data/spec/code/object/time_spec.rb +16 -0
- data/spec/code_spec.rb +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db2e3764ef913582377bf7eec05c2ff854a243e86669bcbf8e0f25b34ccba2f8
|
|
4
|
+
data.tar.gz: 2294044a144455333e0c7cf83f1ffeb0b341eb7a38270babe533c64ebec9c692
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 774f3cc5a9a0f9e1ebce8d0153bd32740274f49ccd1a7e88c98b665a3bbfdb59671c83014fba45d9a468e021405b904a20aca0a38340a596f689363ef4edd014
|
|
7
|
+
data.tar.gz: 179c0905bbb91a14b5109941a69a6109001645bfd7c04180f272c33a4ab601c22de455567f4449febbbb1badea67d64698cbc1c5fba5e1b549fcbb682338316d
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.8.
|
|
1
|
+
1.8.4
|
data/lib/code/object/list.rb
CHANGED
|
@@ -227,8 +227,8 @@ class Code
|
|
|
227
227
|
sig(args)
|
|
228
228
|
code_sum
|
|
229
229
|
when "uniq"
|
|
230
|
-
sig(args)
|
|
231
|
-
code_uniq
|
|
230
|
+
sig(args) { (Function | Class).maybe }
|
|
231
|
+
code_uniq(code_value, **globals)
|
|
232
232
|
when "many?"
|
|
233
233
|
sig(args)
|
|
234
234
|
code_many?
|
|
@@ -1001,8 +1001,39 @@ class Code
|
|
|
1001
1001
|
Integer.new(raw.size)
|
|
1002
1002
|
end
|
|
1003
1003
|
|
|
1004
|
-
def code_uniq
|
|
1005
|
-
|
|
1004
|
+
def code_uniq(argument = nil, **globals)
|
|
1005
|
+
code_argument = argument.to_code
|
|
1006
|
+
|
|
1007
|
+
unless code_argument.is_a?(Function) || code_argument.is_a?(Class)
|
|
1008
|
+
return List.new(raw.uniq)
|
|
1009
|
+
end
|
|
1010
|
+
|
|
1011
|
+
if code_argument.is_a?(Class)
|
|
1012
|
+
return List.new(
|
|
1013
|
+
raw
|
|
1014
|
+
.select { |code_element| code_element.is_a?(code_argument.raw) }
|
|
1015
|
+
.uniq
|
|
1016
|
+
)
|
|
1017
|
+
end
|
|
1018
|
+
|
|
1019
|
+
index = 0
|
|
1020
|
+
|
|
1021
|
+
List.new(
|
|
1022
|
+
raw.uniq do |code_element|
|
|
1023
|
+
if code_argument.is_a?(Function)
|
|
1024
|
+
code_argument
|
|
1025
|
+
.call(
|
|
1026
|
+
arguments: List.new([code_element, Integer.new(index), self]),
|
|
1027
|
+
**globals
|
|
1028
|
+
)
|
|
1029
|
+
.tap { index += 1 }
|
|
1030
|
+
else
|
|
1031
|
+
code_element.tap { index += 1 }
|
|
1032
|
+
end
|
|
1033
|
+
rescue Error::Next => e
|
|
1034
|
+
e.code_value.tap { index += 1 }
|
|
1035
|
+
end
|
|
1036
|
+
)
|
|
1006
1037
|
end
|
|
1007
1038
|
|
|
1008
1039
|
def code_sum
|
data/lib/code/object/time.rb
CHANGED
|
@@ -74,6 +74,17 @@ class Code
|
|
|
74
74
|
self.raw = args.first.to_time.in_time_zone(::Time.zone)
|
|
75
75
|
elsif args.first.is_a?(::ActiveSupport::TimeWithZone)
|
|
76
76
|
self.raw = args.first.dup
|
|
77
|
+
elsif args.first.is_a?(Integer) || args.first.is_a?(Decimal) ||
|
|
78
|
+
args.first.is_a?(::Integer) || args.first.is_a?(::Float) ||
|
|
79
|
+
args.first.is_a?(::BigDecimal)
|
|
80
|
+
code_value = args.first.to_code
|
|
81
|
+
timestamp =
|
|
82
|
+
if code_value.is_a?(Decimal)
|
|
83
|
+
code_value.raw.to_r
|
|
84
|
+
else
|
|
85
|
+
code_value.raw
|
|
86
|
+
end
|
|
87
|
+
self.raw = ::Time.zone.at(timestamp)
|
|
77
88
|
else
|
|
78
89
|
self.raw = ::Time.zone.now
|
|
79
90
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Code::Object::Time do
|
|
6
|
+
[
|
|
7
|
+
['Time.new(1).format("%s")', ":1"],
|
|
8
|
+
['Time.new(1100042342).format("%s")', ":1100042342"],
|
|
9
|
+
['Time.new(1.2).format("%s.%L")', '"1.200"'],
|
|
10
|
+
['Time.new(11212.1212).format("%s.%L")', '"11212.121"']
|
|
11
|
+
].each do |input, expected|
|
|
12
|
+
it "#{input} == #{expected}" do
|
|
13
|
+
expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/spec/code_spec.rb
CHANGED
|
@@ -284,6 +284,9 @@ RSpec.describe Code do
|
|
|
284
284
|
["[1, 2, 3].map { |i| next(0) if i.even? i ** 2}", "[1, 0, 9]"],
|
|
285
285
|
["[1, 2, 3].select { |n| n.even? }", "[2]"],
|
|
286
286
|
["[1, 2, 3].select { |n| n.even? }.select { |n| n.odd? }", "[]"],
|
|
287
|
+
["[1, 2, 3, 4].uniq { |n| n % 2 }", "[1, 2]"],
|
|
288
|
+
['[1, "1", 2, "2"].uniq(String)', '["1", "2"]'],
|
|
289
|
+
["[1, 2, 3, 4].uniq(String)", "[]"],
|
|
287
290
|
["[1, 2].map(&:to_string)", "[:1, :2]"],
|
|
288
291
|
["[1, 2].map(&:to_string)", '["1", "2"]'],
|
|
289
292
|
["[1, 2].map(&:to_string)", '["1", "2"]'],
|
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.8.
|
|
4
|
+
version: 1.8.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Marié
|
|
@@ -345,6 +345,7 @@ files:
|
|
|
345
345
|
- spec/code/object/nothing_spec.rb
|
|
346
346
|
- spec/code/object/range_spec.rb
|
|
347
347
|
- spec/code/object/string_spec.rb
|
|
348
|
+
- spec/code/object/time_spec.rb
|
|
348
349
|
- spec/code/parser/boolean_spec.rb
|
|
349
350
|
- spec/code/parser/chained_call_spec.rb
|
|
350
351
|
- spec/code/parser/dictionary_spec.rb
|