fbe 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fbe/award.rb +44 -23
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_award.rb +15 -1
- 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: 8edc085f571054934f0175c084473ad75477dc2c591a4dfbe20bd85bd00ab364
|
4
|
+
data.tar.gz: 1792731b5d49d6b1a4a2d0c5671cb9dca05843e4af8a7cc7df64bddeb97525bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eaee3b757f8140044a2162f936a92b5b0b259f2e3995fc3032c6a529a9e2d77021506c09ff7910b0272a70b520189ef9f651e0b630f3d63918d400ccb3a6f16
|
7
|
+
data.tar.gz: 62504126787332608ab3a5a178c3946f52bf184e2ff7de2c9fca0b74f208f56437d50c944ff71a67169a66d27d9544c298e322ad320591ddae34c65c76941c49
|
data/lib/fbe/award.rb
CHANGED
@@ -145,31 +145,31 @@ class Fbe::Award
|
|
145
145
|
when :total
|
146
146
|
'total'
|
147
147
|
when :if
|
148
|
-
"if #{
|
148
|
+
"if #{to_p(@operands[0])} then #{to_p(@operands[1])} else #{to_p(@operands[2])}"
|
149
149
|
when :eq
|
150
|
-
"#{
|
150
|
+
"#{to_p(@operands[0])} == #{to_p(@operands[1])}"
|
151
151
|
when :lt
|
152
|
-
"#{
|
152
|
+
"#{to_p(@operands[0])} < #{to_p(@operands[1])}"
|
153
153
|
when :lte
|
154
|
-
"#{
|
154
|
+
"#{to_p(@operands[0])} ≤ #{to_p(@operands[1])}"
|
155
155
|
when :gt
|
156
|
-
"#{
|
156
|
+
"#{to_p(@operands[0])} > #{to_p(@operands[1])}"
|
157
157
|
when :gte
|
158
|
-
"#{
|
158
|
+
"#{to_p(@operands[0])} ≥ #{to_p(@operands[1])}"
|
159
159
|
when :div
|
160
|
-
"#{
|
160
|
+
"#{to_p(@operands[0])} ÷ #{to_p(@operands[1])}"
|
161
161
|
when :times
|
162
|
-
"#{
|
162
|
+
"#{to_p(@operands[0])} × #{to_p(@operands[1])}"
|
163
163
|
when :plus
|
164
|
-
"#{
|
164
|
+
"#{to_p(@operands[0])} + #{to_p(@operands[1])}"
|
165
165
|
when :minus
|
166
|
-
"#{
|
166
|
+
"#{to_p(@operands[0])} - #{to_p(@operands[1])}"
|
167
167
|
when :max
|
168
|
-
"maximum of #{
|
168
|
+
"maximum of #{to_p(@operands[0])} and #{to_p(@operands[1])}"
|
169
169
|
when :min
|
170
|
-
"minimum of #{
|
170
|
+
"minimum of #{to_p(@operands[0])} and #{to_p(@operands[1])}"
|
171
171
|
when :between
|
172
|
-
"at least #{
|
172
|
+
"at least #{to_p(@operands[0])} and at most #{to_p(@operands[1])}"
|
173
173
|
else
|
174
174
|
raise "Unknown term '#{@op}'"
|
175
175
|
end
|
@@ -184,25 +184,42 @@ class Fbe::Award
|
|
184
184
|
raise "Failure in #{o}: #{e.message}"
|
185
185
|
end
|
186
186
|
when :explain
|
187
|
-
policy.intro(
|
187
|
+
policy.intro(to_p(@operands[0]))
|
188
188
|
when :in
|
189
|
-
policy.line("assume that #{
|
189
|
+
policy.line("assume that #{to_p(@operands[0])} is #{to_p(@operands[1])}")
|
190
190
|
when :let
|
191
|
-
policy.line("let #{
|
191
|
+
policy.line("let #{to_p(@operands[0])} be equal to #{to_p(@operands[1])}")
|
192
192
|
when :set
|
193
|
-
policy.line("set #{
|
193
|
+
policy.line("set #{to_p(@operands[0])} to #{to_p(@operands[1])}")
|
194
194
|
when :give
|
195
|
-
policy.line("award #{
|
195
|
+
policy.line("award #{to_p(@operands[0])}")
|
196
196
|
else
|
197
197
|
raise "Unknown term '#{@op}'"
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
-
def
|
202
|
-
|
201
|
+
def to_p(any)
|
202
|
+
case any
|
203
|
+
when PTerm
|
203
204
|
any.to_s
|
204
|
-
|
205
|
-
|
205
|
+
when Symbol
|
206
|
+
s = any.to_s
|
207
|
+
subs = {
|
208
|
+
0 => '₀',
|
209
|
+
1 => '₁',
|
210
|
+
2 => '₂',
|
211
|
+
3 => '₃',
|
212
|
+
4 => '₄',
|
213
|
+
5 => '₅',
|
214
|
+
6 => '₆',
|
215
|
+
7 => '₇',
|
216
|
+
8 => '₈',
|
217
|
+
9 => '₉'
|
218
|
+
}
|
219
|
+
s.gsub!(/([a-z]+)([0-9])/) { |_| "#{Regexp.last_match[1]}#{subs[Regexp.last_match[2].to_i]}" }
|
220
|
+
"_#{s.gsub('_', '\\_')}_"
|
221
|
+
when Integer, Float
|
222
|
+
"**#{any}**"
|
206
223
|
else
|
207
224
|
any
|
208
225
|
end
|
@@ -256,7 +273,11 @@ class Fbe::Award
|
|
256
273
|
end
|
257
274
|
|
258
275
|
def markdown
|
259
|
-
|
276
|
+
pars = []
|
277
|
+
pars << "#{@intro}." unless @intro.empty?
|
278
|
+
pars << 'Here is how it\'s calculated:'
|
279
|
+
pars += @lines.each_with_index.map { |t, i| "#{i.zero? ? 'First' : 'Then'}, #{t}." }
|
280
|
+
pars.join(' ').gsub('. Then, award ', ', and award ')
|
260
281
|
end
|
261
282
|
end
|
262
283
|
end
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_award.rb
CHANGED
@@ -67,7 +67,7 @@ class TestAward < Minitest::Test
|
|
67
67
|
md = a.policy.markdown
|
68
68
|
[
|
69
69
|
'First, assume that _hours_ is hours',
|
70
|
-
'
|
70
|
+
', and award _b₂_'
|
71
71
|
].each { |t| assert(md.include?(t), md) }
|
72
72
|
end
|
73
73
|
|
@@ -83,4 +83,18 @@ class TestAward < Minitest::Test
|
|
83
83
|
assert_equal(v, a.bill.points, q)
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
def test_some_policies
|
88
|
+
{
|
89
|
+
'(award (let x 25) (set z (plus x 1)) (give z "..."))' =>
|
90
|
+
'First, let _x_ be equal to **25**. Then, set _z_ to _x_ + **1**, and award _z_.'
|
91
|
+
# '(award (let x 25) (give x "..."))' =>
|
92
|
+
# 'The amount is **25**.',
|
93
|
+
# '(award (let x -5) (give x "..."))' =>
|
94
|
+
# 'The amount is **-5**.',
|
95
|
+
}.each do |q, t|
|
96
|
+
md = Fbe::Award.new(q).policy.markdown
|
97
|
+
assert(md.include?(t), md)
|
98
|
+
end
|
99
|
+
end
|
86
100
|
end
|
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.20
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|