fbe 0.0.22 → 0.0.23
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 +4 -2
- data/lib/fbe/award.rb +28 -3
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_award.rb +11 -1
- data/test/test__helper.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b13ad3c8a5578c4a9e248948cab63ae21caeea7052d96260f2be85a43ee6f3b8
|
4
|
+
data.tar.gz: 90f8b081a67be3fd2f94a92cea890abb9b93f9b4b11a37a7bc6502f704c16510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea216f0e9be56b06ae8e350ea89b341f9d9fc230ca7785f5b0c0a494fcba3de913143e9c0c5d7074eea3ad368520bfaa462f891c5daf744b4ababbf05e600e8
|
7
|
+
data.tar.gz: 28c70598550a0e68ad1315fee0adce8ebeb31a7eb400f348181c0f916b3b5aac646a1d4f8d51d79f70e5553f3a4a88b33ba4afd67f2075a735cb578ea5312f0c
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# FactBase Extended
|
1
|
+
# FactBase Extended (FBE)
|
2
2
|
|
3
3
|
[](http://www.rultor.com/p/zerocracy/fbe)
|
4
4
|
[](https://www.jetbrains.com/ruby/)
|
@@ -13,12 +13,14 @@
|
|
13
13
|
|
14
14
|
It's a collection of tools for
|
15
15
|
[zerocracy/judges-action](https://github.com/zerocracy/judges-action).
|
16
|
+
You are not supposed to use it directly, but only in a combination
|
17
|
+
with other tools of Zerocracy.
|
16
18
|
|
17
19
|
## How to contribute
|
18
20
|
|
19
21
|
Read
|
20
22
|
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
21
|
-
Make sure
|
23
|
+
Make sure your build is green before you contribute
|
22
24
|
your pull request. You will need to have
|
23
25
|
[Ruby](https://www.ruby-lang.org/en/) 3.2+ and
|
24
26
|
[Bundler](https://bundler.io/) installed. Then:
|
data/lib/fbe/award.rb
CHANGED
@@ -24,7 +24,25 @@
|
|
24
24
|
|
25
25
|
require 'factbase/syntax'
|
26
26
|
|
27
|
-
#
|
27
|
+
# A generator of awards.
|
28
|
+
#
|
29
|
+
# First, you should create a policy, using the same Lisp-ish syntax as
|
30
|
+
# we use in queries to a Factbase, for example:
|
31
|
+
#
|
32
|
+
# require 'fbe/award'
|
33
|
+
# a = Fbe::Award.new('(award (in loc "lines") (give (times loc 5) "for LoC"))')
|
34
|
+
#
|
35
|
+
# Then, you can either get a bill from it:
|
36
|
+
#
|
37
|
+
# b = a.bill(loc: 345)
|
38
|
+
# puts b.points # how many points to reward, a number
|
39
|
+
# puts b.greeting # how to explain the reward, a text
|
40
|
+
#
|
41
|
+
# Or else, you can get a policy text:
|
42
|
+
#
|
43
|
+
# p = a.policy
|
44
|
+
# puts p.markdown # Markdown of the policy
|
45
|
+
#
|
28
46
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
47
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
48
|
# License:: MIT
|
@@ -266,7 +284,14 @@ class Fbe::Award
|
|
266
284
|
|
267
285
|
def greeting
|
268
286
|
items = @lines.map { |l| "#{format('%+d', l[:v])} #{l[:t]}" }
|
269
|
-
|
287
|
+
case items.size
|
288
|
+
when 0
|
289
|
+
"You've earned nothing. "
|
290
|
+
when 1
|
291
|
+
"You've earned #{format('%+d', points)} points. "
|
292
|
+
else
|
293
|
+
"You've earned #{format('%+d', points)} points for this: #{items.join('; ')}. "
|
294
|
+
end
|
270
295
|
end
|
271
296
|
end
|
272
297
|
|
@@ -289,7 +314,7 @@ class Fbe::Award
|
|
289
314
|
end
|
290
315
|
|
291
316
|
def line(line)
|
292
|
-
line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| @lets[Regexp.last_match[1].to_sym] }
|
317
|
+
line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| "**#{@lets[Regexp.last_match[1].to_sym]}**" }
|
293
318
|
@lines << line
|
294
319
|
end
|
295
320
|
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_award.rb
CHANGED
@@ -92,10 +92,20 @@ class TestAward < Minitest::Test
|
|
92
92
|
'(award (let x_a 25) (set z (plus x_a 1)) (give z "..."))' =>
|
93
93
|
'First, let _x-a_ be equal to **25**. Then, set _z_ to _x-a_ + **1**, and award _z_.',
|
94
94
|
'(award (aka (let x 17) (give x "hey") "add ${x} when necessary"))' =>
|
95
|
-
'Just add 17 when necessary'
|
95
|
+
'Just add **17** when necessary'
|
96
96
|
}.each do |q, t|
|
97
97
|
md = Fbe::Award.new(q).policy.markdown
|
98
98
|
assert(md.include?(t), md)
|
99
99
|
end
|
100
100
|
end
|
101
|
+
|
102
|
+
def test_shorten_when_one_number
|
103
|
+
g = Fbe::Award.new('(award (give 23 "for love"))').bill.greeting
|
104
|
+
assert_equal('You\'ve earned +23 points. ', g, g)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_shorten_when_nothing
|
108
|
+
g = Fbe::Award.new('(award (give 0 "for none"))').bill.greeting
|
109
|
+
assert_equal('You\'ve earned nothing. ', g, g)
|
110
|
+
end
|
101
111
|
end
|
data/test/test__helper.rb
CHANGED
@@ -22,6 +22,9 @@
|
|
22
22
|
|
23
23
|
$stdout.sync = true
|
24
24
|
|
25
|
+
require 'minitest/reporters'
|
26
|
+
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
27
|
+
|
25
28
|
require 'simplecov'
|
26
29
|
SimpleCov.start
|
27
30
|
|
@@ -29,6 +32,3 @@ require 'simplecov-cobertura'
|
|
29
32
|
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
30
33
|
|
31
34
|
require 'minitest/autorun'
|
32
|
-
|
33
|
-
require 'minitest/reporters'
|
34
|
-
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|