factbase 0.16.8 → 0.17.0
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 +2 -1
- data/Gemfile.lock +23 -18
- data/README.md +28 -27
- data/Rakefile +14 -6
- data/lib/factbase/cached/cached_query.rb +2 -0
- data/lib/factbase/indexed/indexed_absent.rb +25 -0
- data/lib/factbase/indexed/indexed_and.rb +79 -0
- data/lib/factbase/indexed/indexed_eq.rb +46 -0
- data/lib/factbase/indexed/indexed_exists.rb +25 -0
- data/lib/factbase/indexed/indexed_factbase.rb +46 -0
- data/lib/factbase/indexed/indexed_gt.rb +41 -0
- data/lib/factbase/indexed/indexed_lt.rb +41 -0
- data/lib/factbase/indexed/indexed_not.rb +32 -0
- data/lib/factbase/indexed/indexed_one.rb +25 -0
- data/lib/factbase/indexed/indexed_or.rb +28 -0
- data/lib/factbase/indexed/indexed_query.rb +2 -0
- data/lib/factbase/indexed/indexed_term.rb +29 -185
- data/lib/factbase/indexed/indexed_unique.rb +25 -0
- data/lib/factbase/query.rb +3 -1
- data/lib/factbase/sync/sync_factbase.rb +11 -11
- data/lib/factbase/sync/sync_query.rb +7 -8
- data/lib/factbase/term.rb +110 -91
- data/lib/factbase/terms/absent.rb +26 -0
- data/lib/factbase/terms/aggregates.rb +0 -13
- data/lib/factbase/terms/always.rb +27 -0
- data/lib/factbase/terms/and.rb +28 -0
- data/lib/factbase/terms/arithmetic.rb +55 -0
- data/lib/factbase/terms/as.rb +31 -0
- data/lib/factbase/terms/{debug.rb → assert.rb} +17 -15
- data/lib/factbase/terms/base.rb +17 -0
- data/lib/factbase/terms/boolean.rb +28 -0
- data/lib/factbase/terms/compare.rb +38 -0
- data/lib/factbase/terms/concat.rb +26 -0
- data/lib/factbase/terms/count.rb +25 -0
- data/lib/factbase/terms/defn.rb +16 -15
- data/lib/factbase/terms/div.rb +25 -0
- data/lib/factbase/terms/either.rb +31 -0
- data/lib/factbase/terms/env.rb +28 -0
- data/lib/factbase/terms/eq.rb +28 -0
- data/lib/factbase/terms/exists.rb +27 -0
- data/lib/factbase/terms/first.rb +30 -0
- data/lib/factbase/terms/gt.rb +28 -0
- data/lib/factbase/terms/gte.rb +27 -0
- data/lib/factbase/terms/head.rb +37 -0
- data/lib/factbase/terms/inverted.rb +34 -0
- data/lib/factbase/terms/{aliases.rb → join.rb} +15 -15
- data/lib/factbase/terms/logical.rb +0 -83
- data/lib/factbase/terms/lt.rb +28 -0
- data/lib/factbase/terms/lte.rb +28 -0
- data/lib/factbase/terms/many.rb +29 -0
- data/lib/factbase/terms/{strings.rb → matches.rb} +12 -12
- data/lib/factbase/terms/minus.rb +25 -0
- data/lib/factbase/terms/never.rb +26 -0
- data/lib/factbase/terms/nil.rb +26 -0
- data/lib/factbase/terms/not.rb +27 -0
- data/lib/factbase/terms/one.rb +30 -0
- data/lib/factbase/terms/or.rb +28 -0
- data/lib/factbase/terms/plus.rb +27 -0
- data/lib/factbase/terms/prev.rb +29 -0
- data/lib/factbase/terms/shared.rb +69 -0
- data/lib/factbase/terms/size.rb +30 -0
- data/lib/factbase/terms/sorted.rb +38 -0
- data/lib/factbase/terms/sprintf.rb +29 -0
- data/lib/factbase/terms/times.rb +25 -0
- data/lib/factbase/terms/to_float.rb +28 -0
- data/lib/factbase/terms/to_integer.rb +28 -0
- data/lib/factbase/terms/to_string.rb +28 -0
- data/lib/factbase/terms/to_time.rb +28 -0
- data/lib/factbase/terms/traced.rb +33 -0
- data/lib/factbase/terms/type.rb +31 -0
- data/lib/factbase/terms/undef.rb +33 -0
- data/lib/factbase/terms/unique.rb +34 -0
- data/lib/factbase/terms/when.rb +29 -0
- data/lib/factbase/terms/zero.rb +28 -0
- data/lib/factbase/version.rb +1 -1
- data/lib/factbase.rb +10 -1
- metadata +60 -10
- data/lib/factbase/terms/casting.rb +0 -41
- data/lib/factbase/terms/lists.rb +0 -57
- data/lib/factbase/terms/math.rb +0 -103
- data/lib/factbase/terms/meta.rb +0 -58
- data/lib/factbase/terms/ordering.rb +0 -34
- data/lib/factbase/terms/system.rb +0 -19
data/lib/factbase/terms/math.rb
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
|
-
# SPDX-License-Identifier: MIT
|
|
5
|
-
|
|
6
|
-
require_relative '../../factbase'
|
|
7
|
-
|
|
8
|
-
# Math terms.
|
|
9
|
-
#
|
|
10
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
|
-
# License:: MIT
|
|
13
|
-
module Factbase::Math
|
|
14
|
-
def plus(fact, maps, fb)
|
|
15
|
-
_arithmetic(:+, fact, maps, fb)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def minus(fact, maps, fb)
|
|
19
|
-
_arithmetic(:-, fact, maps, fb)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def times(fact, maps, fb)
|
|
23
|
-
_arithmetic(:*, fact, maps, fb)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def div(fact, maps, fb)
|
|
27
|
-
_arithmetic(:/, fact, maps, fb)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def zero(fact, maps, fb)
|
|
31
|
-
assert_args(1)
|
|
32
|
-
vv = _values(0, fact, maps, fb)
|
|
33
|
-
return false if vv.nil?
|
|
34
|
-
vv.any? { |v| (v.is_a?(Integer) || v.is_a?(Float)) && v.zero? }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def eq(fact, maps, fb)
|
|
38
|
-
_cmp(:==, fact, maps, fb)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def lt(fact, maps, fb)
|
|
42
|
-
_cmp(:<, fact, maps, fb)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def gt(fact, maps, fb)
|
|
46
|
-
_cmp(:>, fact, maps, fb)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def lte(fact, maps, fb)
|
|
50
|
-
_cmp(:<=, fact, maps, fb)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def gte(fact, maps, fb)
|
|
54
|
-
_cmp(:>=, fact, maps, fb)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def _cmp(op, fact, maps, fb)
|
|
58
|
-
assert_args(2)
|
|
59
|
-
lefts = _values(0, fact, maps, fb)
|
|
60
|
-
return false if lefts.nil?
|
|
61
|
-
rights = _values(1, fact, maps, fb)
|
|
62
|
-
return false if rights.nil?
|
|
63
|
-
lefts.any? do |l|
|
|
64
|
-
l = l.floor if l.is_a?(Time) && op == :==
|
|
65
|
-
rights.any? do |r|
|
|
66
|
-
r = r.floor if r.is_a?(Time) && op == :==
|
|
67
|
-
l.send(op, r)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def _arithmetic(op, fact, maps, fb)
|
|
73
|
-
assert_args(2)
|
|
74
|
-
lefts = _values(0, fact, maps, fb)
|
|
75
|
-
return nil if lefts.nil?
|
|
76
|
-
raise 'Too many values at first position, one expected' unless lefts.size == 1
|
|
77
|
-
rights = _values(1, fact, maps, fb)
|
|
78
|
-
return nil if rights.nil?
|
|
79
|
-
raise 'Too many values at second position, one expected' unless rights.size == 1
|
|
80
|
-
v = lefts[0]
|
|
81
|
-
r = rights[0]
|
|
82
|
-
if v.is_a?(Time) && r.is_a?(String)
|
|
83
|
-
(num, units) = r.split
|
|
84
|
-
num = num.to_i
|
|
85
|
-
r =
|
|
86
|
-
case units
|
|
87
|
-
when 'seconds', 'second'
|
|
88
|
-
num
|
|
89
|
-
when 'minutes', 'minute'
|
|
90
|
-
num * 60
|
|
91
|
-
when 'hours', 'hour'
|
|
92
|
-
num * 60 * 60
|
|
93
|
-
when 'days', 'day'
|
|
94
|
-
num * 60 * 60 * 24
|
|
95
|
-
when 'weeks', 'week'
|
|
96
|
-
num * 60 * 60 * 24 * 7
|
|
97
|
-
else
|
|
98
|
-
raise "Unknown time unit '#{units}' in '#{r}"
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
v.send(op, r)
|
|
102
|
-
end
|
|
103
|
-
end
|
data/lib/factbase/terms/meta.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
|
-
# SPDX-License-Identifier: MIT
|
|
5
|
-
|
|
6
|
-
require_relative '../../factbase'
|
|
7
|
-
|
|
8
|
-
# Meta terms.
|
|
9
|
-
#
|
|
10
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
|
-
# License:: MIT
|
|
13
|
-
module Factbase::Meta
|
|
14
|
-
def exists(fact, _maps, _fb)
|
|
15
|
-
assert_args(1)
|
|
16
|
-
!_by_symbol(0, fact).nil?
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def absent(fact, _maps, _fb)
|
|
20
|
-
assert_args(1)
|
|
21
|
-
_by_symbol(0, fact).nil?
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def size(fact, _maps, _fb)
|
|
25
|
-
assert_args(1)
|
|
26
|
-
v = _by_symbol(0, fact)
|
|
27
|
-
return 0 if v.nil?
|
|
28
|
-
return 1 unless v.respond_to?(:to_a)
|
|
29
|
-
v.size
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def type(fact, _maps, _fb)
|
|
33
|
-
assert_args(1)
|
|
34
|
-
v = _by_symbol(0, fact)
|
|
35
|
-
return 'nil' if v.nil?
|
|
36
|
-
v = v[0] if v.respond_to?(:each) && v.size == 1
|
|
37
|
-
v.class.to_s
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def nil(fact, maps, fb)
|
|
41
|
-
assert_args(1)
|
|
42
|
-
_values(0, fact, maps, fb).nil?
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# The property has many (more than one) values.
|
|
46
|
-
def many(fact, maps, fb)
|
|
47
|
-
assert_args(1)
|
|
48
|
-
v = _values(0, fact, maps, fb)
|
|
49
|
-
!v.nil? && v.size > 1
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# The property has exactly one value.
|
|
53
|
-
def one(fact, maps, fb)
|
|
54
|
-
assert_args(1)
|
|
55
|
-
v = _values(0, fact, maps, fb)
|
|
56
|
-
!v.nil? && v.size == 1
|
|
57
|
-
end
|
|
58
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
|
-
# SPDX-License-Identifier: MIT
|
|
5
|
-
|
|
6
|
-
require_relative '../../factbase'
|
|
7
|
-
|
|
8
|
-
# Ordering terms.
|
|
9
|
-
#
|
|
10
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
|
-
# License:: MIT
|
|
13
|
-
module Factbase::Ordering
|
|
14
|
-
def prev(fact, maps, fb)
|
|
15
|
-
assert_args(1)
|
|
16
|
-
before = @prev
|
|
17
|
-
v = _values(0, fact, maps, fb)
|
|
18
|
-
@prev = v
|
|
19
|
-
before
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def unique(fact, maps, fb)
|
|
23
|
-
@seen = Set.new if @seen.nil?
|
|
24
|
-
raise "Too few operands for 'unique' (at least 1 expected)" if @operands.empty?
|
|
25
|
-
vv = (0..(@operands.size - 1)).map { |i| _values(i, fact, maps, fb) }
|
|
26
|
-
return false if vv.any?(nil)
|
|
27
|
-
pass = true
|
|
28
|
-
Enumerator.product(*vv).to_a.each do |t|
|
|
29
|
-
pass = false if @seen.include?(t)
|
|
30
|
-
@seen << t
|
|
31
|
-
end
|
|
32
|
-
pass
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
|
-
# SPDX-License-Identifier: MIT
|
|
5
|
-
|
|
6
|
-
require_relative '../../factbase'
|
|
7
|
-
|
|
8
|
-
# System-level terms.
|
|
9
|
-
#
|
|
10
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
|
-
# License:: MIT
|
|
13
|
-
module Factbase::System
|
|
14
|
-
def env(fact, maps, fb)
|
|
15
|
-
assert_args(2)
|
|
16
|
-
n = _values(0, fact, maps, fb)[0]
|
|
17
|
-
ENV.fetch(n.upcase) { _values(1, fact, maps, fb)[0] }
|
|
18
|
-
end
|
|
19
|
-
end
|