factbase 0.0.58 → 0.0.60
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/README.md +5 -0
- data/lib/factbase/term.rb +1 -1
- data/lib/factbase/terms/ordering.rb +2 -2
- data/lib/factbase/terms/strings.rb +10 -0
- data/lib/factbase.rb +1 -1
- data/test/factbase/terms/test_math.rb +1 -1
- data/test/factbase/terms/test_strings.rb +52 -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: ebfb3fe82bdf543291f6fd7630c2b69deb3949e6788b79d85c5d58ea733240b3
|
4
|
+
data.tar.gz: 38d05a0630a444f8a77e67b96a3f90aa213ec5f47b764c25401fd90320449ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f84d7e12a5cd5b4260590cc40f0a74afa500bec5aaad9f8f3e2c0673fc7864ef9a7c7ac30d08bd5015c3fb87f23cf7123b2ae54306ba58d15c0d0d834f350c
|
7
|
+
data.tar.gz: 1aab5b40d3f47148377d302284af4bed085580bafb4de9acc7b3b9c602e502bdfd3814063095c33f80f63439fe213d190aa9067c55e93c00662f1c3556aa8287
|
data/README.md
CHANGED
@@ -72,6 +72,11 @@ or `b1` is `false`
|
|
72
72
|
* `(gt v1 v2)` — if any `v1` is greater than any `v2`
|
73
73
|
* `(many v)` — if `v` has many values
|
74
74
|
* `(one v)` — if `v` has one value
|
75
|
+
|
76
|
+
There are string manipulators:
|
77
|
+
|
78
|
+
* `(concat v1 v2 v3 ...)` — concatenates all `v`
|
79
|
+
* `(sprintf v v1 v2 ...)` — creates a string by `v` format with params
|
75
80
|
* `(matches v s)` — if any `v` matches the `s` regular expression
|
76
81
|
|
77
82
|
There are a few terms that return non-boolean values:
|
data/lib/factbase/term.rb
CHANGED
@@ -95,7 +95,7 @@ class Factbase::Term
|
|
95
95
|
def evaluate(fact, maps)
|
96
96
|
send(@op, fact, maps)
|
97
97
|
rescue NoMethodError => e
|
98
|
-
raise "
|
98
|
+
raise "Probably the term '#{@op}' is not defined at #{self}:\n#{Backtrace.new(e)}"
|
99
99
|
rescue StandardError => e
|
100
100
|
raise "#{e.message} at #{self}:\n#{Backtrace.new(e)}"
|
101
101
|
end
|
@@ -36,10 +36,10 @@ module Factbase::Term::Ordering
|
|
36
36
|
before
|
37
37
|
end
|
38
38
|
|
39
|
-
def unique(fact,
|
39
|
+
def unique(fact, maps)
|
40
40
|
@uniques = [] if @uniques.nil?
|
41
41
|
assert_args(1)
|
42
|
-
vv =
|
42
|
+
vv = the_values(0, fact, maps)
|
43
43
|
return false if vv.nil?
|
44
44
|
vv = [vv] unless vv.is_a?(Array)
|
45
45
|
vv.each do |v|
|
@@ -28,6 +28,16 @@ require_relative '../../factbase'
|
|
28
28
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
29
29
|
# License:: MIT
|
30
30
|
module Factbase::Term::Strings
|
31
|
+
def concat(fact, maps)
|
32
|
+
(0..@operands.length - 1).map { |i| the_values(i, fact, maps)&.first }.join
|
33
|
+
end
|
34
|
+
|
35
|
+
def sprintf(fact, maps)
|
36
|
+
fmt = the_values(0, fact, maps)[0]
|
37
|
+
ops = (1..@operands.length - 1).map { |i| the_values(i, fact, maps)&.first }
|
38
|
+
format(*([fmt] + ops))
|
39
|
+
end
|
40
|
+
|
31
41
|
def matches(fact, maps)
|
32
42
|
assert_args(2)
|
33
43
|
str = the_values(0, fact, maps)
|
data/lib/factbase.rb
CHANGED
@@ -81,7 +81,7 @@ require 'yaml'
|
|
81
81
|
# License:: MIT
|
82
82
|
class Factbase
|
83
83
|
# Current version of the gem (changed by .rultor.yml on every release)
|
84
|
-
VERSION = '0.0.
|
84
|
+
VERSION = '0.0.60'
|
85
85
|
|
86
86
|
# An exception that may be thrown in a transaction, to roll it back.
|
87
87
|
class Rollback < StandardError; end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'minitest/autorun'
|
24
|
+
require_relative '../../../lib/factbase/term'
|
25
|
+
|
26
|
+
# Strings test.
|
27
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
29
|
+
# License:: MIT
|
30
|
+
class TestStrings < Minitest::Test
|
31
|
+
def test_concat
|
32
|
+
t = Factbase::Term.new(:concat, [42, 'hi', 3.14, :hey, Time.now])
|
33
|
+
s = t.evaluate(fact, [])
|
34
|
+
assert(s.start_with?('42hi3.14'), s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_concat_empty
|
38
|
+
t = Factbase::Term.new(:concat, [])
|
39
|
+
assert_equal('', t.evaluate(fact, []))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_sprintf
|
43
|
+
t = Factbase::Term.new(:sprintf, ['hi, %s!', 'Jeff', :hey])
|
44
|
+
assert_equal('hi, Jeff!', t.evaluate(fact, []))
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def fact(map = {})
|
50
|
+
Factbase::Fact.new(Mutex.new, map)
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.60
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- test/factbase/terms/test_aggregates.rb
|
185
185
|
- test/factbase/terms/test_aliases.rb
|
186
186
|
- test/factbase/terms/test_math.rb
|
187
|
+
- test/factbase/terms/test_strings.rb
|
187
188
|
- test/factbase/test_accum.rb
|
188
189
|
- test/factbase/test_fact.rb
|
189
190
|
- test/factbase/test_flatten.rb
|