factbase 0.0.1 → 0.0.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 +4 -4
- data/.github/workflows/codecov.yml +0 -2
- data/Gemfile +1 -0
- data/lib/factbase/term.rb +13 -1
- data/lib/factbase.rb +5 -1
- data/test/factbase/test_term.rb +12 -0
- data/test/test__helper.rb +3 -1
- data/test/test_factbase.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870d9d422444751180a6e69d1be17c9f89ac46e168d7fc1023e7df22829f9134
|
4
|
+
data.tar.gz: 21e5886fc43c7f297a5f0dd4070d738efb4d6b2ff1f1b9d261d0007bf9ce483d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91992d0fe70646084d7da8091ca5659a3f1aa64c474cfbf328278d40b0e5bc56233abb3b316435660ca3522afd3af275c29291b4f178136ef0544cf173a6d243
|
7
|
+
data.tar.gz: 97c605569af192e7f6960c0bac50777134acb917aa2085b6195d89be95687cde606084569db351025c7c0d4472247feb5f394af1e346a9f14c6af7d5422c2242
|
data/Gemfile
CHANGED
@@ -29,4 +29,5 @@ gem 'rspec-rails', '6.1.2', require: false
|
|
29
29
|
gem 'rubocop', '1.63.5', require: false
|
30
30
|
gem 'rubocop-rspec', '2.29.2', require: false
|
31
31
|
gem 'simplecov', '0.22.0', require: false
|
32
|
+
gem 'simplecov-cobertura', '2.1.0', require: false
|
32
33
|
gem 'yard', '0.9.36', require: false
|
data/lib/factbase/term.rb
CHANGED
@@ -55,10 +55,12 @@ class Factbase::Term
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def nil(_map)
|
58
|
+
assert_args(0)
|
58
59
|
true
|
59
60
|
end
|
60
61
|
|
61
62
|
def not(map)
|
63
|
+
assert_args(1)
|
62
64
|
!@operands[0].matches?(map)
|
63
65
|
end
|
64
66
|
|
@@ -77,23 +79,27 @@ class Factbase::Term
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def exists(map)
|
82
|
+
assert_args(1)
|
80
83
|
k = @operands[0].to_s
|
81
84
|
!map[k].nil?
|
82
85
|
end
|
83
86
|
|
84
87
|
def absent(map)
|
88
|
+
assert_args(1)
|
85
89
|
k = @operands[0].to_s
|
86
90
|
map[k].nil?
|
87
91
|
end
|
88
92
|
|
89
93
|
def eq(map)
|
94
|
+
assert_args(2)
|
90
95
|
k = @operands[0].to_s
|
91
96
|
v = map[k]
|
92
97
|
return false if v.nil?
|
93
|
-
v
|
98
|
+
v.include?(@operands[1])
|
94
99
|
end
|
95
100
|
|
96
101
|
def lt(map)
|
102
|
+
assert_args(2)
|
97
103
|
k = @operands[0].to_s
|
98
104
|
v = map[k]
|
99
105
|
return false if v.nil?
|
@@ -101,9 +107,15 @@ class Factbase::Term
|
|
101
107
|
end
|
102
108
|
|
103
109
|
def gt(map)
|
110
|
+
assert_args(2)
|
104
111
|
k = @operands[0].to_s
|
105
112
|
v = map[k]
|
106
113
|
return false if v.nil?
|
107
114
|
v[0] > @operands[1]
|
108
115
|
end
|
116
|
+
|
117
|
+
def assert_args(num)
|
118
|
+
raise "Too many operands for '#{@op}'" if @operands.size > num
|
119
|
+
raise "Too few operands for '#{@op}'" if @operands.size < num
|
120
|
+
end
|
109
121
|
end
|
data/lib/factbase.rb
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
# License:: MIT
|
27
27
|
class Factbase
|
28
28
|
# Current version of the library and of this class.
|
29
|
-
VERSION = '0.0.
|
29
|
+
VERSION = '0.0.2'
|
30
30
|
|
31
31
|
# Constructor.
|
32
32
|
def initialize
|
@@ -77,6 +77,10 @@ class Factbase
|
|
77
77
|
@maps += Marshal.load(bytes)
|
78
78
|
# rubocop:enable Security/MarshalLoad
|
79
79
|
end
|
80
|
+
|
81
|
+
def to_json(_ = nil)
|
82
|
+
@maps.to_json
|
83
|
+
end
|
80
84
|
end
|
81
85
|
|
82
86
|
require_relative 'factbase/fact'
|
data/test/factbase/test_term.rb
CHANGED
@@ -36,6 +36,12 @@ class TestTerm < Minitest::Test
|
|
36
36
|
assert(!t.matches?({ 'bar' => ['Hello!'] }))
|
37
37
|
end
|
38
38
|
|
39
|
+
def test_eq_matching
|
40
|
+
t = Factbase::Term.new(:eq, ['foo', 42])
|
41
|
+
assert(t.matches?({ 'foo' => [10, 5, 6, -8, 'hey', 42, 9, 'fdsf'] }))
|
42
|
+
assert(!t.matches?({ 'foo' => [100] }))
|
43
|
+
end
|
44
|
+
|
39
45
|
def test_lt_matching
|
40
46
|
t = Factbase::Term.new(:lt, ['foo', 42])
|
41
47
|
assert(t.matches?({ 'foo' => [10] }))
|
@@ -53,6 +59,12 @@ class TestTerm < Minitest::Test
|
|
53
59
|
assert(!t.matches?({ 'foo' => [100] }))
|
54
60
|
end
|
55
61
|
|
62
|
+
def test_not_exists_matching
|
63
|
+
t = Factbase::Term.new(:not, [Factbase::Term.new(:eq, ['foo', 100])])
|
64
|
+
assert(t.matches?({ 'foo' => [42, 12, -90] }))
|
65
|
+
assert(!t.matches?({ 'foo' => [100] }))
|
66
|
+
end
|
67
|
+
|
56
68
|
def test_or_matching
|
57
69
|
t = Factbase::Term.new(
|
58
70
|
:or,
|
data/test/test__helper.rb
CHANGED
data/test/test_factbase.rb
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
# SOFTWARE.
|
23
23
|
|
24
24
|
require 'minitest/autorun'
|
25
|
+
require 'json'
|
25
26
|
require_relative '../lib/factbase'
|
26
27
|
|
27
28
|
# Factbase main module test.
|
@@ -53,4 +54,13 @@ class TestFactbase < Minitest::Test
|
|
53
54
|
end
|
54
55
|
assert_equal(1, f2.query('(eq foo 42)').to_a.count)
|
55
56
|
end
|
57
|
+
|
58
|
+
def test_to_json
|
59
|
+
fb = Factbase.new
|
60
|
+
f = fb.insert
|
61
|
+
f.foo = 42
|
62
|
+
f.foo = 256
|
63
|
+
json = JSON.parse(fb.to_json)
|
64
|
+
assert(42, json[0]['foo'][1])
|
65
|
+
end
|
56
66
|
end
|