fbe 0.0.20 → 0.0.21
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 +32 -3
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_award.rb +9 -8
- 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: a57f0e5f562ad6ac7400355614f0af933b2130470759a877d34ea35878a4e52c
|
4
|
+
data.tar.gz: 0c93b9b7d1de5cf6f2c5bac41f71b663e19d7c1af667f5e6a41c53a361392afc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ec9cb12e7388c4260e9740255af73d8993e5b05abb0ee613bde3ee87e140a9b4b2bb1177c3dd14025e2a83c3eb3f87e8f5b84293f2b52256491860dd67b0807
|
7
|
+
data.tar.gz: e11c60c5bedc1abe4eb68702285c8a76f08c03e3b3e76a3dbf01f8ab514a1c024e1af0f1b38408cff5b5e7d370e011e5da1fee7d9c11e0be50d8e0ccd641de89
|
data/lib/fbe/award.rb
CHANGED
@@ -67,6 +67,12 @@ class Fbe::Award
|
|
67
67
|
rescue StandardError => e
|
68
68
|
raise "Failure in #{o}: #{e.message}"
|
69
69
|
end
|
70
|
+
when :aka
|
71
|
+
@operands[0..-2].each do |o|
|
72
|
+
o.bill_to(bill)
|
73
|
+
rescue StandardError => e
|
74
|
+
raise "Failure in #{o}: #{e.message}"
|
75
|
+
end
|
70
76
|
when :let, :set
|
71
77
|
bill.set(@operands[0], to_val(@operands[1], bill))
|
72
78
|
when :give
|
@@ -147,7 +153,7 @@ class Fbe::Award
|
|
147
153
|
when :if
|
148
154
|
"if #{to_p(@operands[0])} then #{to_p(@operands[1])} else #{to_p(@operands[2])}"
|
149
155
|
when :eq
|
150
|
-
"#{to_p(@operands[0])}
|
156
|
+
"#{to_p(@operands[0])} = #{to_p(@operands[1])}"
|
151
157
|
when :lt
|
152
158
|
"#{to_p(@operands[0])} < #{to_p(@operands[1])}"
|
153
159
|
when :lte
|
@@ -183,12 +189,21 @@ class Fbe::Award
|
|
183
189
|
rescue StandardError => e
|
184
190
|
raise "Failure in #{o}: #{e.message}"
|
185
191
|
end
|
192
|
+
when :aka
|
193
|
+
@operands[0..-2].each do |o|
|
194
|
+
o.publish_to(policy)
|
195
|
+
rescue StandardError => e
|
196
|
+
raise "Failure in #{o}: #{e.message}"
|
197
|
+
end
|
198
|
+
policy.revert(@operands.size - 1)
|
199
|
+
policy.line(to_p(@operands[@operands.size - 1]))
|
186
200
|
when :explain
|
187
201
|
policy.intro(to_p(@operands[0]))
|
188
202
|
when :in
|
189
203
|
policy.line("assume that #{to_p(@operands[0])} is #{to_p(@operands[1])}")
|
190
204
|
when :let
|
191
205
|
policy.line("let #{to_p(@operands[0])} be equal to #{to_p(@operands[1])}")
|
206
|
+
policy.let(@operands[0], @operands[1])
|
192
207
|
when :set
|
193
208
|
policy.line("set #{to_p(@operands[0])} to #{to_p(@operands[1])}")
|
194
209
|
when :give
|
@@ -217,7 +232,7 @@ class Fbe::Award
|
|
217
232
|
9 => '₉'
|
218
233
|
}
|
219
234
|
s.gsub!(/([a-z]+)([0-9])/) { |_| "#{Regexp.last_match[1]}#{subs[Regexp.last_match[2].to_i]}" }
|
220
|
-
"_#{s.gsub('_', '
|
235
|
+
"_#{s.gsub('_', '-')}_"
|
221
236
|
when Integer, Float
|
222
237
|
"**#{any}**"
|
223
238
|
else
|
@@ -262,6 +277,11 @@ class Fbe::Award
|
|
262
277
|
def initialize
|
263
278
|
@lines = []
|
264
279
|
@intro = ''
|
280
|
+
@lets = {}
|
281
|
+
end
|
282
|
+
|
283
|
+
def revert(num)
|
284
|
+
@lines.slice!(-num, num)
|
265
285
|
end
|
266
286
|
|
267
287
|
def intro(text)
|
@@ -269,14 +289,23 @@ class Fbe::Award
|
|
269
289
|
end
|
270
290
|
|
271
291
|
def line(line)
|
292
|
+
line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| @lets[Regexp.last_match[1].to_sym] }
|
272
293
|
@lines << line
|
273
294
|
end
|
274
295
|
|
296
|
+
def let(key, value)
|
297
|
+
@lets[key] = value
|
298
|
+
end
|
299
|
+
|
275
300
|
def markdown
|
276
301
|
pars = []
|
277
302
|
pars << "#{@intro}." unless @intro.empty?
|
278
303
|
pars << 'Here is how it\'s calculated:'
|
279
|
-
|
304
|
+
if @lines.size == 1
|
305
|
+
pars << "Just #{@lines.first}."
|
306
|
+
else
|
307
|
+
pars += @lines.each_with_index.map { |t, i| "#{i.zero? ? 'First' : 'Then'}, #{t}." }
|
308
|
+
end
|
280
309
|
pars.join(' ').gsub('. Then, award ', ', and award ')
|
281
310
|
end
|
282
311
|
end
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_award.rb
CHANGED
@@ -40,8 +40,11 @@ class TestAward < Minitest::Test
|
|
40
40
|
(let max 36)
|
41
41
|
(let basis 30)
|
42
42
|
(give basis "as a basis")
|
43
|
-
(
|
44
|
-
(
|
43
|
+
(let fee 10)
|
44
|
+
(aka
|
45
|
+
(set b1 (if (lt hours max) fee 0))
|
46
|
+
(give b1 "for resolving the bug in ${hours} (<${max}) hours")
|
47
|
+
"add ${+fee} if it was resolved in less than ${max} hours")
|
45
48
|
(set days (div hours 24))
|
46
49
|
(set b2 (times days -1))
|
47
50
|
(let worst -20)
|
@@ -86,12 +89,10 @@ class TestAward < Minitest::Test
|
|
86
89
|
|
87
90
|
def test_some_policies
|
88
91
|
{
|
89
|
-
'(award (let
|
90
|
-
'First, let
|
91
|
-
|
92
|
-
|
93
|
-
# '(award (let x -5) (give x "..."))' =>
|
94
|
-
# 'The amount is **-5**.',
|
92
|
+
'(award (let x_a 25) (set z (plus x_a 1)) (give z "..."))' =>
|
93
|
+
'First, let _x-a_ be equal to **25**. Then, set _z_ to _x-a_ + **1**, and award _z_.',
|
94
|
+
'(award (aka (let x 17) (give x "hey") "add ${x} when necessary"))' =>
|
95
|
+
'Just add 17 when necessary'
|
95
96
|
}.each do |q, t|
|
96
97
|
md = Fbe::Award.new(q).policy.markdown
|
97
98
|
assert(md.include?(t), md)
|