code-ruby 0.9.0 → 0.9.2

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: 53b06f45f6875d9e78c0554c660567fcfc7837b2e3fc3bfa8f3773bbdf133831
4
- data.tar.gz: 894638c2797c729099e577a8c7f10d21990d291a0cc2376760f5e61d58f0c6e4
3
+ metadata.gz: 2a15136e1a9999fb8cba9a433f0e72d6bd237b8de8d0c948477824944853da2d
4
+ data.tar.gz: 98a7b20d9225d717865eaa8fa461fa660e970a281f9de464725fd3923c0dee9f
5
5
  SHA512:
6
- metadata.gz: 387dde40ad9948f938cdaea2a94dfcaabe4e94cef99f8941340184287a8b79efcd378f1012d3a0b4215b394090efc51368b9770429a5b60e63804721487c3546
7
- data.tar.gz: a5939cfca0ff262ac86075c141cb133b39126f0f99f61b4715a018e3f746a45513dce30b4a45520a5f95117cbd67716a6984236199ef45b6d527853a31dae3f0
6
+ metadata.gz: 998e06a88b8d4bfb4cd1529c01a5ea347b3f1874c5c11ddbe9952942db999cb25bba645c5f49bfdb40ff7f17a217af035561ad58fcb06dd8c4383d8906362947
7
+ data.tar.gz: b9a5b0703efca344bdd1f1f0b972ddabad86746cbd6745eb71c2a82ef61fc4a30370bd7052dfe703e1a44055926f17c9a57005ff5b353057dc462078c148ea80
@@ -10,14 +10,6 @@ class Code
10
10
  @name = name
11
11
  end
12
12
 
13
- def self.name
14
- "Argument"
15
- end
16
-
17
- def inspect
18
- to_s
19
- end
20
-
21
13
  def keyword?
22
14
  !regular?
23
15
  end
@@ -29,10 +21,6 @@ class Code
29
21
  def regular?
30
22
  !name
31
23
  end
32
-
33
- def to_s
34
- "<Argument #{value.inspect}>"
35
- end
36
24
  end
37
25
  end
38
26
  end
@@ -6,7 +6,11 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw)
9
- @raw = raw
9
+ if raw.is_a?(Object)
10
+ @raw = raw.truthy?
11
+ else
12
+ @raw = !!raw
13
+ end
10
14
  end
11
15
 
12
16
  def self.name
@@ -60,6 +64,10 @@ class Code
60
64
  def truthy?
61
65
  raw
62
66
  end
67
+
68
+ def as_json(...)
69
+ raw.as_json(...)
70
+ end
63
71
  end
64
72
  end
65
73
  end
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw)
9
+ raw = raw.raw if raw.is_a?(Class)
9
10
  @raw = raw
10
11
  end
11
12
 
@@ -24,6 +25,10 @@ class Code
24
25
  def self.name
25
26
  "Class"
26
27
  end
28
+
29
+ def as_json(...)
30
+ raw.name.as_json(...)
31
+ end
27
32
  end
28
33
  end
29
34
  end
@@ -6,7 +6,8 @@ class Code
6
6
  attr_reader :parent
7
7
 
8
8
  def initialize(raw = {}, parent: nil)
9
- @raw = raw
9
+ raw = raw.raw if raw.is_a?(Dictionary)
10
+ @raw = raw.to_h
10
11
  @parent = parent
11
12
  end
12
13
 
@@ -6,7 +6,8 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(date)
9
- @raw = date
9
+ date = date.raw if date.is_a?(Date)
10
+ @raw = date.to_date
10
11
  end
11
12
 
12
13
  def self.name
@@ -37,6 +38,10 @@ class Code
37
38
  def to_s
38
39
  raw.to_s
39
40
  end
41
+
42
+ def as_json(...)
43
+ raw.as_json(...)
44
+ end
40
45
  end
41
46
  end
42
47
  end
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(decimal, exponent: nil)
9
+ decimal = decimal.raw if decimal.is_a?(Decimal)
9
10
  @raw = BigDecimal(decimal)
10
11
 
11
12
  return unless exponent
@@ -309,6 +310,10 @@ class Code
309
310
  def to_s
310
311
  raw.to_s("F")
311
312
  end
313
+
314
+ def as_json(...)
315
+ raw.as_json(...)
316
+ end
312
317
  end
313
318
  end
314
319
  end
@@ -6,7 +6,8 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw = {})
9
- @raw = raw
9
+ raw = raw.raw if raw.is_a?(Dictionary)
10
+ @raw = raw.to_h
10
11
  end
11
12
 
12
13
  def self.name
@@ -648,6 +649,10 @@ class Code
648
649
  def to_s
649
650
  "{#{raw.map { |key, value| "#{key.inspect} => #{value.inspect}" }.join(", ")}}"
650
651
  end
652
+
653
+ def as_json(...)
654
+ raw.as_json(...)
655
+ end
651
656
  end
652
657
  end
653
658
  end
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(duration)
9
+ duration = duration.raw if duration.is_a?(Duration)
9
10
  @raw = duration
10
11
  end
11
12
 
@@ -43,6 +44,10 @@ class Code
43
44
  def to_s
44
45
  raw.to_s
45
46
  end
47
+
48
+ def as_json(...)
49
+ raw.as_json(...)
50
+ end
46
51
  end
47
52
  end
48
53
  end
@@ -87,6 +87,10 @@ class Code
87
87
  def to_s
88
88
  ""
89
89
  end
90
+
91
+ def as_json(...)
92
+ raw.as_json(...)
93
+ end
90
94
  end
91
95
  end
92
96
  end
@@ -91,10 +91,6 @@ class Code
91
91
  end
92
92
  end
93
93
  end
94
-
95
- def to_s
96
- "global"
97
- end
98
94
  end
99
95
  end
100
96
  end
@@ -403,6 +403,10 @@ class Code
403
403
  def to_s
404
404
  raw.to_s
405
405
  end
406
+
407
+ def as_json(...)
408
+ raw.as_json(...)
409
+ end
406
410
  end
407
411
  end
408
412
  end
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw = [])
9
+ raw = raw.raw if raw.is_a?(List)
9
10
  @raw = raw.to_a
10
11
  end
11
12
 
@@ -211,6 +212,10 @@ class Code
211
212
  def to_s
212
213
  "[#{raw.map(&:inspect).join(", ")}]"
213
214
  end
215
+
216
+ def as_json(...)
217
+ raw.as_json(...)
218
+ end
214
219
  end
215
220
  end
216
221
  end
@@ -24,6 +24,10 @@ class Code
24
24
  def truthy?
25
25
  false
26
26
  end
27
+
28
+ def as_json(...)
29
+ raw.as_json(...)
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -8,7 +8,7 @@ class Code
8
8
  def initialize(left, right, exclude_end: false)
9
9
  @left = left
10
10
  @right = right
11
- @exclude_end = exclude_end
11
+ @exclude_end = !!exclude_end
12
12
  @raw = ::Range.new(left, right, exclude_end)
13
13
  end
14
14
 
@@ -138,6 +138,10 @@ class Code
138
138
  def to_s
139
139
  raw.to_s
140
140
  end
141
+
142
+ def as_json(...)
143
+ raw.as_json(...)
144
+ end
141
145
  end
142
146
  end
143
147
  end
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(string)
9
+ string = string.raw if string.is_a?(String)
9
10
  @raw = string.to_s
10
11
  end
11
12
 
@@ -100,6 +101,10 @@ class Code
100
101
  def to_s
101
102
  raw
102
103
  end
104
+
105
+ def as_json(...)
106
+ raw.as_json(...)
107
+ end
103
108
  end
104
109
  end
105
110
  end
@@ -77,6 +77,10 @@ class Code
77
77
  def to_s
78
78
  raw.to_s
79
79
  end
80
+
81
+ def as_json(...)
82
+ raw.as_json(...)
83
+ end
80
84
  end
81
85
  end
82
86
  end
data/lib/code/object.rb CHANGED
@@ -319,5 +319,13 @@ class Code
319
319
  def truthy?
320
320
  true
321
321
  end
322
+
323
+ def to_json(...)
324
+ as_json(...).to_json
325
+ end
326
+
327
+ def as_json(...)
328
+ raise NotImplementedError, "#{self.class}#as_json"
329
+ end
322
330
  end
323
331
  end
data/lib/code/version.rb CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative "../code"
4
4
 
5
- Code::Version = Gem::Version.new("0.9.0")
5
+ Code::Version = Gem::Version.new("0.9.2")
data/lib/code-ruby.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support"
4
+ require "active_support/core_ext/date/conversions"
5
+ require "active_support/core_ext/numeric/time"
6
+ require "active_support/core_ext/object/json"
3
7
  require "bigdecimal"
8
+ require "json"
9
+ require "language-ruby"
4
10
  require "stringio"
5
11
  require "timeout"
6
12
  require "zeitwerk"
7
- require "language-ruby"
8
- require "active_support"
9
- require "active_support/core_ext/numeric/time"
10
- require "active_support/core_ext/date/conversions"
11
13
 
12
14
  loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
13
15
  loader.ignore("#{__dir__}/code-ruby.rb")
data/spec/code_spec.rb CHANGED
@@ -146,6 +146,10 @@ RSpec.describe Code do
146
146
  it "#{input} == #{expected}" do
147
147
  expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
148
148
  end
149
+
150
+ it "#{input} converts to json like #{expected}" do
151
+ expect(Code.evaluate(input).to_json).to eq(Code.evaluate(expected).to_json)
152
+ end
149
153
  end
150
154
 
151
155
  %w[
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: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié