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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8edc085f571054934f0175c084473ad75477dc2c591a4dfbe20bd85bd00ab364
4
- data.tar.gz: 1792731b5d49d6b1a4a2d0c5671cb9dca05843e4af8a7cc7df64bddeb97525bd
3
+ metadata.gz: a57f0e5f562ad6ac7400355614f0af933b2130470759a877d34ea35878a4e52c
4
+ data.tar.gz: 0c93b9b7d1de5cf6f2c5bac41f71b663e19d7c1af667f5e6a41c53a361392afc
5
5
  SHA512:
6
- metadata.gz: 6eaee3b757f8140044a2162f936a92b5b0b259f2e3995fc3032c6a529a9e2d77021506c09ff7910b0272a70b520189ef9f651e0b630f3d63918d400ccb3a6f16
7
- data.tar.gz: 62504126787332608ab3a5a178c3946f52bf184e2ff7de2c9fca0b74f208f56437d50c944ff71a67169a66d27d9544c298e322ad320591ddae34c65c76941c49
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])} == #{to_p(@operands[1])}"
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
- pars += @lines.each_with_index.map { |t, i| "#{i.zero? ? 'First' : 'Then'}, #{t}." }
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
@@ -27,5 +27,5 @@
27
27
  # License:: MIT
28
28
  module Fbe
29
29
  # Current version of the gem (changed by .rultor.yml on every release)
30
- VERSION = '0.0.20'
30
+ VERSION = '0.0.21'
31
31
  end
@@ -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
- (set b1 (if (lt hours max) 10 0))
44
- (give b1 "for resolving the bug in ${hours} (<${max}) hours")
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 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**.',
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko