teepee 0.12.3 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/teepee/command-parser.rb +12 -0
- data/lib/teepee/commander.rb +80 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ef1d6f0a4ef80b10920bad0277d6f9f10b57795
|
4
|
+
data.tar.gz: 3c9eff8a1f75e84544a6bdca7151985ea669612d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5137fa7ef23f957db297abd29072304c7489bb2b0cad438c66aec6d57d869a482ca445e9832e8e13fdbc298bbede55e698f0e1cdc933aa6780c3839e8c8fd0d2
|
7
|
+
data.tar.gz: 5e472f615093a5a354fd14850af44edfedbbfece1d75d6936f68a12c3d2677d81335514fd86504b223ddd938c392fc15318582d8001782d84a39330dcc4a3bf8
|
@@ -372,6 +372,18 @@ module Teepee
|
|
372
372
|
@@commander.boolean_xor expressions
|
373
373
|
when "xnor"
|
374
374
|
@@commander.boolean_xnor expressions
|
375
|
+
when "<"
|
376
|
+
@@commander.less_than *numbers_from_expressions
|
377
|
+
when "<="
|
378
|
+
@@commander.less_than_or_equal *numbers_from_expressions
|
379
|
+
when ">"
|
380
|
+
@@commander.greater_than *numbers_from_expressions
|
381
|
+
when ">="
|
382
|
+
@@commander.greater_than_or_equal *numbers_from_expressions
|
383
|
+
when "="
|
384
|
+
@@commander.equal *numbers_from_expressions
|
385
|
+
when "!="
|
386
|
+
@@commander.not_equal *numbers_from_expressions
|
375
387
|
when "if"
|
376
388
|
@@commander.if_operator expressions
|
377
389
|
when "do"
|
data/lib/teepee/commander.rb
CHANGED
@@ -61,6 +61,10 @@ module Teepee
|
|
61
61
|
command_error "The command #{command} is not yet implemented."
|
62
62
|
end
|
63
63
|
|
64
|
+
def numeric? *numbers
|
65
|
+
numbers.all? {|number| number.kind_of? Numeric}
|
66
|
+
end
|
67
|
+
|
64
68
|
def ensure_numeric number
|
65
69
|
if number.kind_of? Complex
|
66
70
|
command_error "Complex numbers are not yet supported."
|
@@ -181,22 +185,18 @@ module Teepee
|
|
181
185
|
end
|
182
186
|
|
183
187
|
def % *numbers
|
184
|
-
ensure_numeric numbers
|
185
188
|
numbers.inject { |base, percent| base*percent/100.0 }
|
186
189
|
end
|
187
190
|
|
188
191
|
def add_percentage *numbers
|
189
|
-
ensure_numeric numbers
|
190
192
|
numbers.inject {|base, percent| base * (1+percent/100.0) }
|
191
193
|
end
|
192
194
|
|
193
195
|
def subtract_percentage *numbers
|
194
|
-
ensure_numeric numbers
|
195
196
|
numbers.inject {|base, percent| base * (1-percent/100.0) }
|
196
197
|
end
|
197
198
|
|
198
199
|
def percent_total *numbers
|
199
|
-
ensure_numeric numbers
|
200
200
|
numbers.inject {|total, part| Float(part)/Float(total)*100.0 }
|
201
201
|
end
|
202
202
|
|
@@ -246,10 +246,10 @@ module Teepee
|
|
246
246
|
|
247
247
|
def boolean_and expressions
|
248
248
|
if expressions.empty?
|
249
|
-
|
250
|
-
elsif expressions.first
|
251
|
-
|
252
|
-
elsif expressions.first
|
249
|
+
true_constant
|
250
|
+
elsif false_constant? expressions.first
|
251
|
+
false_constant
|
252
|
+
elsif true_constant? expressions.first or expressions.first.kind_of? WhitespaceToken
|
253
253
|
boolean_and expressions[1..-1]
|
254
254
|
else
|
255
255
|
command_error "Not a boolean value #{expressions.first}"
|
@@ -265,10 +265,10 @@ module Teepee
|
|
265
265
|
end
|
266
266
|
|
267
267
|
def boolean_not expression
|
268
|
-
if expression
|
269
|
-
|
270
|
-
elsif expression
|
271
|
-
|
268
|
+
if true_constant? expression
|
269
|
+
false_constant
|
270
|
+
elsif false_constant? expression
|
271
|
+
true_constant
|
272
272
|
else
|
273
273
|
command_error "Not a boolean value"
|
274
274
|
end
|
@@ -276,10 +276,10 @@ module Teepee
|
|
276
276
|
|
277
277
|
def boolean_or expressions
|
278
278
|
if expressions.empty?
|
279
|
-
|
280
|
-
elsif expressions.first
|
281
|
-
|
282
|
-
elsif expressions.first
|
279
|
+
false_constant
|
280
|
+
elsif true_constant? expressions.first
|
281
|
+
true_constant
|
282
|
+
elsif false_constant? expressions.first or expressions.first.kind_of? WhitespaceToken
|
283
283
|
boolean_or expressions[1..-1]
|
284
284
|
else
|
285
285
|
command_error "Not a boolean value"
|
@@ -297,17 +297,17 @@ module Teepee
|
|
297
297
|
# I'm going with the second: one and only one true, the rest false.
|
298
298
|
# It seems therefore that the zero-argument version should be false then.
|
299
299
|
if expressions.empty?
|
300
|
-
|
300
|
+
false_constant
|
301
301
|
else
|
302
302
|
any_trues = false
|
303
303
|
expressions.each do |expression|
|
304
|
-
if expression
|
304
|
+
if true_constant? expression
|
305
305
|
if any_trues
|
306
|
-
return
|
306
|
+
return false_constant
|
307
307
|
else
|
308
308
|
any_trues = true
|
309
309
|
end
|
310
|
-
elsif expression
|
310
|
+
elsif false_constant? expression
|
311
311
|
# do nothing
|
312
312
|
elsif expression.kind_of? WhitespaceToken
|
313
313
|
# do nothing
|
@@ -351,6 +351,16 @@ module Teepee
|
|
351
351
|
Math::E
|
352
352
|
end
|
353
353
|
|
354
|
+
def equal *numbers
|
355
|
+
if numbers.empty?
|
356
|
+
true_constant
|
357
|
+
elsif numbers.length == 1
|
358
|
+
true_constant
|
359
|
+
else
|
360
|
+
numbers[0] == numbers[1] and equal *numbers.rest
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
354
364
|
def enumerate expressions
|
355
365
|
html_tag :ol, expressions
|
356
366
|
end
|
@@ -399,6 +409,26 @@ module Teepee
|
|
399
409
|
ensure_numeric Math.gamma number
|
400
410
|
end
|
401
411
|
|
412
|
+
def greater_than *numbers
|
413
|
+
if numbers.empty?
|
414
|
+
true_constant
|
415
|
+
elsif numbers.length == 1
|
416
|
+
true_constant
|
417
|
+
else
|
418
|
+
numbers[0] > numbers[1] and greater_than *numbers.rest
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
def greater_than_or_equal *numbers
|
423
|
+
if numbers.empty?
|
424
|
+
true_constant
|
425
|
+
elsif numbers.length == 1
|
426
|
+
true_constant
|
427
|
+
else
|
428
|
+
numbers[0] >= numbers[1] and greater_than_or_equal *numbers.rest
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
402
432
|
def h1 expressions
|
403
433
|
html_tag :h1, expressions
|
404
434
|
end
|
@@ -504,6 +534,26 @@ module Teepee
|
|
504
534
|
"["
|
505
535
|
end
|
506
536
|
|
537
|
+
def less_than *numbers
|
538
|
+
if numbers.empty?
|
539
|
+
true_constant
|
540
|
+
elsif numbers.length == 1
|
541
|
+
true_constant
|
542
|
+
else
|
543
|
+
numbers[0] < numbers[1] and less_than *numbers.rest
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
def less_than_or_equal *numbers
|
548
|
+
if numbers.empty?
|
549
|
+
true_constant
|
550
|
+
elsif numbers.length == 1
|
551
|
+
true_constant
|
552
|
+
else
|
553
|
+
numbers[0] <= numbers[1] and less_than_or_equal *numbers.rest
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
507
557
|
def lgamma n
|
508
558
|
ensure_numeric Math::lgamma(n).first
|
509
559
|
end
|
@@ -559,6 +609,16 @@ module Teepee
|
|
559
609
|
" " * count
|
560
610
|
end
|
561
611
|
|
612
|
+
def not_equal *numbers
|
613
|
+
if numbers.empty?
|
614
|
+
true_constant
|
615
|
+
elsif numbers.length == 1
|
616
|
+
true_constant
|
617
|
+
else
|
618
|
+
numbers[0] != numbers[1] and equal *numbers.rest
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
562
622
|
def note_id id
|
563
623
|
id_command_handler id, :Note
|
564
624
|
end
|