teepee 0.15.2 → 0.15.3

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
  SHA1:
3
- metadata.gz: 3ab55219c597cb80dc9422180444fc557212c07b
4
- data.tar.gz: b3b3817de233269cf0a345ed5f7a054727439f3d
3
+ metadata.gz: 64473abc28a1538dcbe1cf68ee8ab8f5dd8ec4c8
4
+ data.tar.gz: 185b231a0b949d9f6203ec1f056447383b819bcc
5
5
  SHA512:
6
- metadata.gz: 889ace53cc915c231a75edb002b35a5936986e392bfbddc0dbbacbd442150dfe2f1246bc97b5aa0bd51c6f22a316c70275b1de37cf18d7ce672c53dc2a2f9f40
7
- data.tar.gz: 97f7168451eb2023b26617e04716ca12d083fd77557bf7d0097187a25f800af0af428575f555311bc27728415827ef33a0c790e9bd931a8035f0a30a648feedf
6
+ metadata.gz: 348895f88f009067449af5a2db530d9e31382c3b03f8d60e7e3f17d3f3ede12bf077ab0b548e3b38281f719a3d0d819aa0d0b15a54d269918252ca3ca084209f
7
+ data.tar.gz: 54987b1dd30100e24a51e3cad6db9defdc4f675b583c868204518294918f48d7fa22bc8d10396d571b63808e89e561eefaf346f960b914f479d52c8b387745da
@@ -318,6 +318,12 @@ module Teepee
318
318
  @@commander.e
319
319
  when "+"
320
320
  @@commander.+ word_tokens
321
+ when "increment",
322
+ "inc"
323
+ @@commander.increment first_word_token
324
+ when "decrement",
325
+ "dec"
326
+ @@commander.decrement first_word_token
321
327
  when "-"
322
328
  @@commander.- word_tokens
323
329
  when "*"
@@ -442,7 +448,7 @@ module Teepee
442
448
  "undef"
443
449
  @@commander.undefine expressions
444
450
  when "defined?"
445
- @@commander.defined? word_tokens
451
+ @@commander.is_defined? word_tokens
446
452
  when "dotimes"
447
453
  @@commander.dotimes expressions
448
454
  else
@@ -57,10 +57,18 @@ module Teepee
57
57
  command_error "The command #{command} is not yet implemented."
58
58
  end
59
59
 
60
+ def variable_not_defined_error variable
61
+ command_error "The variable \"#{variable}\" is not defined."
62
+ end
63
+
60
64
  def numeric? *numbers
61
65
  numbers.all? {|number| number.kind_of? Numeric}
62
66
  end
63
67
 
68
+ def non_numeric_error nan
69
+ command_error "The value \"#{nan}\" is not a number."
70
+ end
71
+
64
72
  def ensure_numeric number
65
73
  if number.kind_of? Complex
66
74
  command_error "Complex numbers are not yet supported."
@@ -377,6 +385,13 @@ module Teepee
377
385
  ensure_numeric Math.cosh angle.to_number
378
386
  end
379
387
 
388
+ def decrement variable
389
+ return variable_not_defined_error variable if not is_defined? variable
390
+ old_value = get_operator(variable).to_number
391
+ return non_numeric_error old_value if not numeric? old_value
392
+ @parser.variables[variable.to_html] = old_value - 1
393
+ end
394
+
380
395
  def define expressions
381
396
  variable, _, value = expressions
382
397
  k = variable.to_html
@@ -385,8 +400,10 @@ module Teepee
385
400
  get_operator k
386
401
  end
387
402
 
388
- def defined? variables
389
- if Set.new(variables.map(&:to_html)).subset? Set.new(@parser.variables.keys)
403
+ def is_defined? variables
404
+ if not variables.is_a? Array
405
+ return is_defined? [variables]
406
+ elsif Set.new(variables.map(&:to_html)).subset? Set.new(@parser.variables.keys)
390
407
  true_constant
391
408
  else
392
409
  false_constant
@@ -554,6 +571,13 @@ module Teepee
554
571
  end
555
572
  end
556
573
 
574
+ def increment variable
575
+ return variable_not_defined_error variable if not is_defined? variable
576
+ old_value = get_operator(variable).to_number
577
+ return non_numeric_error old_value if not numeric? old_value
578
+ @parser.variables[variable.to_html] = old_value + 1
579
+ end
580
+
557
581
  def it expressions
558
582
  html_tag :i, expressions
559
583
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teepee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.2
4
+ version: 0.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mark Gore