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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d25c37b43cfba051943236b5a62e33f24e64569c638cabe65aff2a9bca5823dd
4
- data.tar.gz: 99870b5a82826ea29fee426e357c6cf51533ad480c14a7b46a8a408a238b4a91
3
+ metadata.gz: 8edc085f571054934f0175c084473ad75477dc2c591a4dfbe20bd85bd00ab364
4
+ data.tar.gz: 1792731b5d49d6b1a4a2d0c5671cb9dca05843e4af8a7cc7df64bddeb97525bd
5
5
  SHA512:
6
- metadata.gz: 64c1b1d1be331458fe3c34a99a80c81f5bf2e77a6e7b378d1269d5c421024e049b61cdf5651ccd435b7a1233eb8d315e8e39f8d04091cbcf813468e1417b94e0
7
- data.tar.gz: b2feba50e12a9b157b09cbea421f87c97d50201afc0da2619f144f1b6963937718ffdf4fc050995d8c8b7c38798955989bb7b4dcf6d14f0c525c451c8002e738
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 #{to_str(@operands[0])} then #{to_str(@operands[1])} else #{to_str(@operands[2])}"
148
+ "if #{to_p(@operands[0])} then #{to_p(@operands[1])} else #{to_p(@operands[2])}"
149
149
  when :eq
150
- "#{to_str(@operands[0])} == #{to_str(@operands[1])}"
150
+ "#{to_p(@operands[0])} == #{to_p(@operands[1])}"
151
151
  when :lt
152
- "#{to_str(@operands[0])} < #{to_str(@operands[1])}"
152
+ "#{to_p(@operands[0])} < #{to_p(@operands[1])}"
153
153
  when :lte
154
- "#{to_str(@operands[0])} ≤ #{to_str(@operands[1])}"
154
+ "#{to_p(@operands[0])} ≤ #{to_p(@operands[1])}"
155
155
  when :gt
156
- "#{to_str(@operands[0])} > #{to_str(@operands[1])}"
156
+ "#{to_p(@operands[0])} > #{to_p(@operands[1])}"
157
157
  when :gte
158
- "#{to_str(@operands[0])} ≥ #{to_str(@operands[1])}"
158
+ "#{to_p(@operands[0])} ≥ #{to_p(@operands[1])}"
159
159
  when :div
160
- "#{to_str(@operands[0])} ÷ #{to_str(@operands[1])}"
160
+ "#{to_p(@operands[0])} ÷ #{to_p(@operands[1])}"
161
161
  when :times
162
- "#{to_str(@operands[0])} × #{to_str(@operands[1])}"
162
+ "#{to_p(@operands[0])} × #{to_p(@operands[1])}"
163
163
  when :plus
164
- "#{to_str(@operands[0])} + #{to_str(@operands[1])}"
164
+ "#{to_p(@operands[0])} + #{to_p(@operands[1])}"
165
165
  when :minus
166
- "#{to_str(@operands[0])} - #{to_str(@operands[1])}"
166
+ "#{to_p(@operands[0])} - #{to_p(@operands[1])}"
167
167
  when :max
168
- "maximum of #{to_str(@operands[0])} and #{to_str(@operands[1])}"
168
+ "maximum of #{to_p(@operands[0])} and #{to_p(@operands[1])}"
169
169
  when :min
170
- "minimum of #{to_str(@operands[0])} and #{to_str(@operands[1])}"
170
+ "minimum of #{to_p(@operands[0])} and #{to_p(@operands[1])}"
171
171
  when :between
172
- "at least #{to_str(@operands[0])} and at most #{to_str(@operands[1])}"
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(to_str(@operands[0]))
187
+ policy.intro(to_p(@operands[0]))
188
188
  when :in
189
- policy.line("assume that #{to_str(@operands[0])} is #{to_str(@operands[1])}")
189
+ policy.line("assume that #{to_p(@operands[0])} is #{to_p(@operands[1])}")
190
190
  when :let
191
- policy.line("let #{to_str(@operands[0])} be equal to #{to_str(@operands[1])}")
191
+ policy.line("let #{to_p(@operands[0])} be equal to #{to_p(@operands[1])}")
192
192
  when :set
193
- policy.line("set #{to_str(@operands[0])} to #{to_str(@operands[1])}")
193
+ policy.line("set #{to_p(@operands[0])} to #{to_p(@operands[1])}")
194
194
  when :give
195
- policy.line("award #{to_str(@operands[0])}")
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 to_str(any)
202
- if any.is_a?(PTerm)
201
+ def to_p(any)
202
+ case any
203
+ when PTerm
203
204
  any.to_s
204
- elsif any.is_a?(Symbol)
205
- "_#{any}_"
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
- "#{@intro}. Here it how it's calculated: First, #{@lines.join('. Then, ')}."
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
@@ -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.19'
30
+ VERSION = '0.0.20'
31
31
  end
@@ -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
- 'Then, award _b2_'
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.19
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-17 00:00:00.000000000 Z
11
+ date: 2024-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace