teepee 0.12.11 → 0.13.0

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: ecf663db7d98476598a43fc1a2f56555ccdc76ee
4
- data.tar.gz: 29fe97871b75e502cb0c01196cdb1f0762efe180
3
+ metadata.gz: 42fae0e05a81b055eff93f9792ca84f040d9ea1a
4
+ data.tar.gz: 099f7492b8b97be7aa1c48257f0b646b71923ec1
5
5
  SHA512:
6
- metadata.gz: 168e130a4d794f1f906e7ad6996b650d4771167748e10f8797bc736d65b383ddac85a6a7c961f40b187abeeb15f98b61d9a9d0d418536f45ebab8fd6bc47eb04
7
- data.tar.gz: f2af3dff36c80878129014eee1302592e3714961beaedf415bd570267eb15385c9519b953ff12193f8014069b1234803c4d03af624508b9d5d13502d5027c6af
6
+ metadata.gz: 3050382db418cdb90fd951a6abfadfe0cca28ea7b5393cc54681d50b2247a69c7002158001ea2efebb08929ce06e455443c79ccf297fb4d95968e04acdd6c4c7
7
+ data.tar.gz: 918acc5ca1a16a90ce520e0aac23d68ba86043d0cc26ff98e437801811786d3cb45134edda35bec21cf084be6a1c290957b98750bf719eade9697ab0b535ceb8
data/lib/teepee.rb CHANGED
@@ -43,6 +43,18 @@ require 'monkey-patch'
43
43
 
44
44
  include ERB::Util
45
45
 
46
+ class Float
47
+ def to_number
48
+ self
49
+ end
50
+ end
51
+
52
+ class Integer
53
+ def to_number
54
+ self
55
+ end
56
+ end
57
+
46
58
  require 'teepee/constants'
47
59
  require 'teepee/errors'
48
60
  require 'teepee/parser-node'
@@ -62,6 +62,10 @@ module Teepee
62
62
  %{<span style="color: red">[#{message}]</span>}
63
63
  end
64
64
 
65
+ def to_number
66
+ to_html.to_number
67
+ end
68
+
65
69
  def to_html
66
70
  case command.word
67
71
  when "backslash",
@@ -116,7 +120,7 @@ module Teepee
116
120
  when "dollar"
117
121
  @@commander.dollar
118
122
  when "_"
119
- @@commander.nbsp optional_number_from_expression
123
+ @@commander.nbsp optional_first_word_token
120
124
  when "space"
121
125
  @@commander.space
122
126
  when "br", "newline"
@@ -302,67 +306,67 @@ module Teepee
302
306
  when "e"
303
307
  @@commander.e
304
308
  when "+"
305
- @@commander.+ *numbers_from_expressions
309
+ @@commander.+ word_tokens
306
310
  when "-"
307
- @@commander.- *numbers_from_expressions
311
+ @@commander.- word_tokens
308
312
  when "*"
309
- @@commander.* *numbers_from_expressions
313
+ @@commander.* word_tokens
310
314
  when "/",
311
315
  "÷"
312
- @@commander./ *numbers_from_expressions
316
+ @@commander./ word_tokens
313
317
  when "%"
314
- @@commander.% *numbers_from_expressions
318
+ @@commander.% word_tokens
315
319
  when "+%"
316
- @@commander.add_percentage *numbers_from_expressions
320
+ @@commander.add_percentage word_tokens
317
321
  when "-%"
318
- @@commander.subtract_percentage *numbers_from_expressions
322
+ @@commander.subtract_percentage word_tokens
319
323
  when "%t",
320
324
  "%total"
321
- @@commander.percent_total *numbers_from_expressions
325
+ @@commander.percent_total word_tokens
322
326
  when "floor"
323
- @@commander.floor number_from_expression
327
+ @@commander.floor first_word_token
324
328
  when "ceil",
325
329
  "ciel",
326
330
  "ceiling"
327
- @@commander.ceiling number_from_expression
331
+ @@commander.ceiling first_word_token
328
332
  when "round"
329
- @@commander.round *numbers_from_expressions
333
+ @@commander.round *word_tokens
330
334
  when "mod",
331
335
  "modulus",
332
336
  "modulo"
333
- @@commander.mod *numbers_from_expressions
337
+ @@commander.mod word_tokens
334
338
  when "^", "**"
335
- @@commander.** *numbers_from_expressions
339
+ @@commander.** word_tokens
336
340
  when "sin", "cos", "tan",
337
341
  "asin", "acos", "atan",
338
342
  "sinh", "cosh", "tanh",
339
343
  "asinh", "acosh", "atanh",
340
344
  "erf", "erfc",
341
345
  "gamma", "log10", "sqrt"
342
- @@commander.send command.word.to_sym, number_from_expression
346
+ @@commander.send command.word.to_sym, first_word_token
343
347
  when "d2r",
344
348
  "deg->rad",
345
349
  "degrees->radians"
346
- @@commander.degrees2radians number_from_expression
350
+ @@commander.degrees2radians first_word_token
347
351
  when "r2d",
348
352
  "rad->deg",
349
353
  "radians->degrees"
350
- @@commander.radians2degrees number_from_expression
354
+ @@commander.radians2degrees first_word_token
351
355
  when "lgamma"
352
- @@commander.lgamma number_from_expression
356
+ @@commander.lgamma first_word_token
353
357
  when "ld",
354
358
  "log2"
355
- @@commander.ld number_from_expression
359
+ @@commander.ld first_word_token
356
360
  when "ln"
357
- @@commander.ln number_from_expression
361
+ @@commander.ln first_word_token
358
362
  when "log"
359
- base, number = numbers_from_expressions
363
+ base, number = word_tokens
360
364
  @@commander.log base, number
361
365
  when "ldexp"
362
- fraction, exponent = numbers_from_expressions
366
+ fraction, exponent = word_tokens
363
367
  @@commander.ldexp fraction, exponent
364
368
  when "hypot"
365
- @@commander.hypot numbers_from_expressions
369
+ @@commander.hypot word_tokens
366
370
  when "true"
367
371
  @@commander.true_constant
368
372
  when "false"
@@ -382,20 +386,20 @@ module Teepee
382
386
  when "xnor"
383
387
  @@commander.boolean_xnor expressions
384
388
  when "<"
385
- @@commander.less_than *numbers_from_expressions
389
+ @@commander.less_than word_tokens
386
390
  when "<=",
387
391
  "≤"
388
- @@commander.less_than_or_equal *numbers_from_expressions
392
+ @@commander.less_than_or_equal word_tokens
389
393
  when ">"
390
- @@commander.greater_than *numbers_from_expressions
394
+ @@commander.greater_than word_tokens
391
395
  when ">=",
392
396
  "≥"
393
- @@commander.greater_than_or_equal *numbers_from_expressions
397
+ @@commander.greater_than_or_equal word_tokens
394
398
  when "="
395
- @@commander.equal *numbers_from_expressions
399
+ @@commander.equal word_tokens
396
400
  when "!=",
397
401
  "≠"
398
- @@commander.not_equal *numbers_from_expressions
402
+ @@commander.not_equal word_tokens
399
403
  when "if"
400
404
  @@commander.if_operator expressions
401
405
  when "when"
@@ -416,6 +420,10 @@ module Teepee
416
420
  @@commander.cond_operator expressions
417
421
  when "case"
418
422
  @@commander.case_operator expressions
423
+ when "get"
424
+ @@commander.get_operator first_word_token
425
+ when "set"
426
+ @@commander.set_operator expressions
419
427
  else
420
428
  command_error "unknown command #{command.to_html}"
421
429
  end
@@ -429,29 +437,16 @@ module Teepee
429
437
  %{<a href="#{TB_COM}/#{target}">#{string}</a>}
430
438
  end
431
439
 
432
- def first_word_token
433
- expressions.select {|expr| expr.is_a? WordToken}.first
434
- end
435
-
436
- def numbers_from_expressions
437
- expressions
438
- .map do |number|
439
- begin
440
- Float(number.to_html)
441
- rescue ArgumentError
442
- nil
443
- end
444
- end.reject &:nil?
440
+ def word_tokens
441
+ expressions.reject {|expr| expr.is_a? WhitespaceToken}
445
442
  end
446
443
 
447
- def number_from_expression
448
- numbers_from_expressions.first
444
+ def first_word_token
445
+ word_tokens.first
449
446
  end
450
447
 
451
- def optional_number_from_expression
452
- if not expressions.empty?
453
- number_from_expression
454
- end
448
+ def optional_first_word_token
449
+ first_word_token if not expressions.empty?
455
450
  end
456
451
 
457
452
  class << self
@@ -37,6 +37,10 @@
37
37
 
38
38
  module Teepee
39
39
  class Commander
40
+ def initialize
41
+ @variables = Hash.new
42
+ end
43
+
40
44
  def valid_uri? uri
41
45
  (!! (u = URI.parse(uri))) and not u.scheme.nil?
42
46
  rescue URI::InvalidURIError
@@ -148,13 +152,26 @@ module Teepee
148
152
  expression.is_a? PipeToken
149
153
  end
150
154
 
155
+ def number_from_word word
156
+ begin
157
+ word.to_number
158
+ rescue ArgumentError, NoMethodError
159
+ nil
160
+ end
161
+ end
162
+
163
+ def to_numbers words
164
+ words.map {|word| number_from_word word}.reject &:nil?
165
+ end
166
+
151
167
  #----------------------------------------------------------------------------
152
168
 
153
- def + *numbers
154
- ensure_numeric numbers.inject 0, :+
169
+ def + numbers
170
+ ensure_numeric to_numbers(numbers).inject 0, :+
155
171
  end
156
172
 
157
- def - *numbers
173
+ def - numbers
174
+ numbers = to_numbers numbers
158
175
  if numbers.length == 1
159
176
  ensure_numeric -numbers.first
160
177
  else
@@ -162,11 +179,12 @@ module Teepee
162
179
  end
163
180
  end
164
181
 
165
- def * *numbers
166
- ensure_numeric numbers.inject 1, :*
182
+ def * numbers
183
+ ensure_numeric to_numbers(numbers).inject 1, :*
167
184
  end
168
185
 
169
- def / *numbers
186
+ def / numbers
187
+ numbers = to_numbers numbers
170
188
  if numbers.length == 1
171
189
  ensure_numeric 1 / numbers.first
172
190
  else
@@ -174,48 +192,48 @@ module Teepee
174
192
  end
175
193
  end
176
194
 
177
- def ** *numbers
178
- ensure_numeric numbers.reduce :**
195
+ def ** numbers
196
+ ensure_numeric to_numbers(numbers).reduce :**
179
197
  end
180
198
 
181
- def % *numbers
182
- numbers.inject { |base, percent| base*percent/100.0 }
199
+ def % numbers
200
+ to_numbers(numbers).inject { |base, percent| base*percent/100.0 }
183
201
  end
184
202
 
185
- def add_percentage *numbers
186
- numbers.inject {|base, percent| base * (1+percent/100.0) }
203
+ def add_percentage numbers
204
+ to_numbers(numbers).inject {|base, percent| base * (1+percent/100.0) }
187
205
  end
188
206
 
189
- def subtract_percentage *numbers
190
- numbers.inject {|base, percent| base * (1-percent/100.0) }
207
+ def subtract_percentage numbers
208
+ to_numbers(numbers).inject {|base, percent| base * (1-percent/100.0) }
191
209
  end
192
210
 
193
- def percent_total *numbers
194
- numbers.inject {|total, part| Float(part)/Float(total)*100.0 }
211
+ def percent_total numbers
212
+ to_numbers(numbers).inject {|total, part| Float(part)/Float(total)*100.0 }
195
213
  end
196
214
 
197
- def acos number
198
- ensure_numeric Math.acos number
215
+ def acos angle
216
+ ensure_numeric Math.acos angle.to_number
199
217
  end
200
218
 
201
- def acosh number
202
- ensure_numeric Math.acosh number
219
+ def acosh angle
220
+ ensure_numeric Math.acosh angle.to_number
203
221
  end
204
222
 
205
- def asin number
206
- ensure_numeric Math.asin number
223
+ def asin angle
224
+ ensure_numeric Math.asin angle.to_number
207
225
  end
208
226
 
209
- def asinh number
210
- ensure_numeric Math.asinh number
227
+ def asinh angle
228
+ ensure_numeric Math.asinh angle.to_number
211
229
  end
212
230
 
213
- def atan number
214
- ensure_numeric Math.atan number
231
+ def atan angle
232
+ ensure_numeric Math.atan angle.to_number
215
233
  end
216
234
 
217
- def atanh number
218
- ensure_numeric Math.atanh number
235
+ def atanh angle
236
+ ensure_numeric Math.atanh angle.to_number
219
237
  end
220
238
 
221
239
  def b expressions
@@ -238,72 +256,72 @@ module Teepee
238
256
  id_command_handler id, :Folder, "folder", "folders", "folders/bookmarks_inline", "bookmarks"
239
257
  end
240
258
 
241
- def boolean_and expressions
242
- if expressions.empty?
259
+ def boolean_and booleans
260
+ if booleans.empty?
243
261
  true_constant
244
- elsif false_constant? expressions.first
262
+ elsif false_constant? booleans.first
245
263
  false_constant
246
- elsif true_constant? expressions.first or expressions.first.kind_of? WhitespaceToken
247
- boolean_and expressions[1..-1]
264
+ elsif true_constant? booleans.first or booleans.first.kind_of? WhitespaceToken
265
+ boolean_and booleans[1..-1]
248
266
  else
249
- command_error "Not a boolean value #{expressions.first}"
267
+ command_error "Not a boolean value #{booleans.first}"
250
268
  end
251
269
  end
252
270
 
253
- def boolean_nand expressions
254
- boolean_not boolean_and expressions
271
+ def boolean_nand booleans
272
+ boolean_not boolean_and booleans
255
273
  end
256
274
 
257
- def boolean_nor expressions
258
- boolean_not boolean_or expressions
275
+ def boolean_nor booleans
276
+ boolean_not boolean_or booleans
259
277
  end
260
278
 
261
- def boolean_not expression
262
- if true_constant? expression
279
+ def boolean_not boolean
280
+ if true_constant? boolean
263
281
  false_constant
264
- elsif false_constant? expression
282
+ elsif false_constant? boolean
265
283
  true_constant
266
284
  else
267
285
  command_error "Not a boolean value"
268
286
  end
269
287
  end
270
288
 
271
- def boolean_or expressions
272
- if expressions.empty?
289
+ def boolean_or booleans
290
+ if booleans.empty?
273
291
  false_constant
274
- elsif true_constant? expressions.first
292
+ elsif true_constant? booleans.first
275
293
  true_constant
276
- elsif false_constant? expressions.first or expressions.first.kind_of? WhitespaceToken
277
- boolean_or expressions[1..-1]
294
+ elsif false_constant? booleans.first or booleans.first.kind_of? WhitespaceToken
295
+ boolean_or booleans[1..-1]
278
296
  else
279
297
  command_error "Not a boolean value"
280
298
  end
281
299
  end
282
300
 
283
- def boolean_xnor expressions
284
- boolean_not boolean_xor expressions
301
+ def boolean_xnor booleans
302
+ boolean_not boolean_xor booleans
285
303
  end
286
304
 
287
- def boolean_xor expressions
305
+ def boolean_xor booleans
288
306
  # There are two schools of thought as to what a multi-variable XOR is.
289
307
  # 1. Chained XORs, giving a parity check.
290
308
  # 2. 'Exclusively' one true for ALL inputs.
291
309
  # I'm going with the second: one and only one true, the rest false.
292
310
  # It seems therefore that the zero-argument version should be false then.
293
- if expressions.empty?
311
+ if booleans.empty?
294
312
  false_constant
295
313
  else
296
314
  any_trues = false
297
- expressions.each do |expression|
298
- if true_constant? expression
315
+ booleans.each do |boolean|
316
+ if true_constant? boolean
299
317
  if any_trues
300
318
  return false_constant
301
319
  else
302
320
  any_trues = true
303
321
  end
304
- elsif false_constant? expression
322
+ elsif false_constant? boolean
305
323
  # do nothing
306
- elsif expression.kind_of? WhitespaceToken
324
+ elsif boolean.kind_of? WhitespaceToken
307
325
  # do nothing
308
326
  else
309
327
  return command_error "Not a boolean value"
@@ -322,7 +340,7 @@ module Teepee
322
340
  if value and not rest.empty?
323
341
  def cond_helper value, expressions
324
342
  test_value, _, form, *rest = strip expressions
325
- if equal value, test_value
343
+ if equal [value, test_value]
326
344
  form
327
345
  elsif not rest.empty?
328
346
  cond_helper value, rest
@@ -333,7 +351,7 @@ module Teepee
333
351
  end
334
352
 
335
353
  def ceiling number
336
- ensure_numeric number.ceil
354
+ ensure_numeric number.to_number.ceil
337
355
  end
338
356
 
339
357
  def comment expressions
@@ -350,15 +368,15 @@ module Teepee
350
368
  end
351
369
 
352
370
  def cos angle
353
- ensure_numeric Math.cos angle
371
+ ensure_numeric Math.cos angle.to_number
354
372
  end
355
373
 
356
- def cosh number
357
- ensure_numeric Math.cosh number
374
+ def cosh angle
375
+ ensure_numeric Math.cosh angle.to_number
358
376
  end
359
377
 
360
378
  def degrees2radians degrees
361
- ensure_numeric degrees * Math::PI / 180.0
379
+ ensure_numeric degrees.to_number * Math::PI / 180.0
362
380
  end
363
381
 
364
382
  def del expressions
@@ -373,13 +391,13 @@ module Teepee
373
391
  Math::E
374
392
  end
375
393
 
376
- def equal *expressions
394
+ def equal expressions
377
395
  if expressions.empty?
378
396
  true_constant
379
397
  elsif expressions.length == 1
380
398
  true_constant
381
399
  else
382
- expressions[0].to_s == expressions[1].to_s and equal *expressions.rest
400
+ expressions[0].to_s == expressions[1].to_s and equal expressions.rest
383
401
  end
384
402
  end
385
403
 
@@ -408,11 +426,11 @@ module Teepee
408
426
  end
409
427
 
410
428
  def erf number
411
- ensure_numeric Math.erf number
429
+ ensure_numeric Math.erf number.to_number
412
430
  end
413
431
 
414
432
  def erfc number
415
- ensure_numeric Math.erfc number
433
+ ensure_numeric Math.erfc number.to_number
416
434
  end
417
435
 
418
436
  def false_constant
@@ -420,7 +438,7 @@ module Teepee
420
438
  end
421
439
 
422
440
  def floor number
423
- ensure_numeric number.floor
441
+ ensure_numeric number.to_number.floor
424
442
  end
425
443
 
426
444
  def folder_id id
@@ -432,26 +450,30 @@ module Teepee
432
450
  end
433
451
 
434
452
  def gamma number
435
- ensure_numeric Math.gamma number
453
+ ensure_numeric Math.gamma number.to_number
454
+ end
455
+
456
+ def get_operator variable
457
+ @variables[variable.to_s]
436
458
  end
437
459
 
438
- def greater_than *numbers
460
+ def greater_than numbers
439
461
  if numbers.empty?
440
462
  true_constant
441
463
  elsif numbers.length == 1
442
464
  true_constant
443
465
  else
444
- numbers[0] > numbers[1] and greater_than *numbers.rest
466
+ numbers[0].to_number > numbers[1].to_number and greater_than numbers.rest
445
467
  end
446
468
  end
447
469
 
448
- def greater_than_or_equal *numbers
470
+ def greater_than_or_equal numbers
449
471
  if numbers.empty?
450
472
  true_constant
451
473
  elsif numbers.length == 1
452
474
  true_constant
453
475
  else
454
- numbers[0] >= numbers[1] and greater_than_or_equal *numbers.rest
476
+ numbers[0].to_number >= numbers[1].to_number and greater_than_or_equal numbers.rest
455
477
  end
456
478
  end
457
479
 
@@ -537,19 +559,19 @@ module Teepee
537
559
  end
538
560
 
539
561
  def hypot numbers
540
- ensure_numeric Math.sqrt numbers.map {|n| n**2}
562
+ ensure_numeric Math.sqrt to_numbers(numbers).map {|n| n**2}
541
563
  end
542
564
 
543
565
  def keyword_id id
544
566
  id_command_handler id, :Keyword
545
567
  end
546
568
 
547
- def ld n
548
- ensure_numeric Math.log2 n
569
+ def ld number
570
+ ensure_numeric Math.log2 number.to_number
549
571
  end
550
572
 
551
573
  def ldexp fraction, exponent
552
- ensure_numeric Math.ldexp fraction, exponent
574
+ ensure_numeric Math.ldexp fraction.to_number, exponent.to_number
553
575
  end
554
576
 
555
577
  def left_brace
@@ -560,28 +582,28 @@ module Teepee
560
582
  "["
561
583
  end
562
584
 
563
- def less_than *numbers
585
+ def less_than numbers
564
586
  if numbers.empty?
565
587
  true_constant
566
588
  elsif numbers.length == 1
567
589
  true_constant
568
590
  else
569
- numbers[0] < numbers[1] and less_than *numbers.rest
591
+ numbers[0].to_number < numbers[1].to_number and less_than numbers.rest
570
592
  end
571
593
  end
572
594
 
573
- def less_than_or_equal *numbers
595
+ def less_than_or_equal numbers
574
596
  if numbers.empty?
575
597
  true_constant
576
598
  elsif numbers.length == 1
577
599
  true_constant
578
600
  else
579
- numbers[0] <= numbers[1] and less_than_or_equal *numbers.rest
601
+ numbers[0].to_number <= numbers[1].to_number and less_than_or_equal numbers.rest
580
602
  end
581
603
  end
582
604
 
583
- def lgamma n
584
- ensure_numeric Math::lgamma(n).first
605
+ def lgamma number
606
+ ensure_numeric Math::lgamma(number.to_number).first
585
607
  end
586
608
 
587
609
  def link expressions
@@ -601,20 +623,20 @@ module Teepee
601
623
  end
602
624
 
603
625
  def ln number
604
- ensure_numeric Math.log number
626
+ ensure_numeric Math.log number.to_number
605
627
  end
606
628
 
607
629
  def log base, number
608
630
  if number.nil?
609
631
  number, base = base, number
610
- ensure_numeric Math.log10 number # default to log base 10
632
+ ensure_numeric Math.log10 number.to_number # default to log base 10
611
633
  else
612
- ensure_numeric Math.log number, base
634
+ ensure_numeric Math.log number.to_number, base.to_number
613
635
  end
614
636
  end
615
637
 
616
638
  def log10 number
617
- ensure_numeric Math.log10 number
639
+ ensure_numeric Math.log10 number.to_number
618
640
  end
619
641
 
620
642
  def mailto email_address
@@ -626,22 +648,25 @@ module Teepee
626
648
  end
627
649
  end
628
650
 
629
- def mod *numbers
630
- ensure_numeric numbers.reduce :%
651
+ def mod numbers
652
+ ensure_numeric to_numbers(numbers).reduce :%
631
653
  end
632
654
 
633
655
  def nbsp count
634
- count = 1 unless count and count.kind_of? Numeric and count > 0
635
- "&nbsp;" * count
656
+ if count and count.to_number and count.to_number > 0
657
+ "&nbsp;" * count.to_number
658
+ else
659
+ "&nbsp;"
660
+ end
636
661
  end
637
662
 
638
- def not_equal *numbers
663
+ def not_equal numbers
639
664
  if numbers.empty?
640
665
  true_constant
641
666
  elsif numbers.length == 1
642
667
  true_constant
643
668
  else
644
- numbers[0] != numbers[1] and equal *numbers.rest
669
+ numbers[0].to_number != numbers[1].to_number and equal numbers.rest
645
670
  end
646
671
  end
647
672
 
@@ -658,15 +683,15 @@ module Teepee
658
683
  end
659
684
 
660
685
  def prog1_operator expressions
661
- expressions.first
686
+ expressions.map(&:to_html).first
662
687
  end
663
688
 
664
689
  def progn_operator expressions
665
- expressions.last
690
+ expressions.map(&:to_html).last
666
691
  end
667
692
 
668
693
  def radians2degrees radians
669
- ensure_numeric(radians * 180.0 / Math::PI)
694
+ ensure_numeric(radians.to_number * 180.0 / Math::PI)
670
695
  end
671
696
 
672
697
  def right_brace
@@ -678,19 +703,24 @@ module Teepee
678
703
  end
679
704
 
680
705
  def round number, precision = nil, *_
681
- if precision.nil?
682
- ensure_numeric number.round
706
+ if precision.nil? or precision.to_number.nil?
707
+ ensure_numeric number.to_number.round
683
708
  else
684
- ensure_numeric number.round precision
709
+ ensure_numeric number.to_number.round precision.to_number
685
710
  end
686
711
  end
687
712
 
713
+ def set_operator expressions
714
+ variable, _, value = expressions
715
+ @variables[variable.to_s] = value
716
+ end
717
+
688
718
  def sin angle
689
- ensure_numeric Math.sin angle
719
+ ensure_numeric Math.sin angle.to_number
690
720
  end
691
721
 
692
- def sinh number
693
- ensure_numeric Math.sinh number
722
+ def sinh angle
723
+ ensure_numeric Math.sinh angle.to_number
694
724
  end
695
725
 
696
726
  def small expressions
@@ -702,7 +732,7 @@ module Teepee
702
732
  end
703
733
 
704
734
  def sqrt number
705
- ensure_numeric Math.sqrt number
735
+ ensure_numeric Math.sqrt number.to_number
706
736
  end
707
737
 
708
738
  def space
@@ -742,11 +772,11 @@ module Teepee
742
772
  end
743
773
 
744
774
  def tan angle
745
- ensure_numeric Math.tan angle
775
+ ensure_numeric Math.tan angle.to_number
746
776
  end
747
777
 
748
- def tanh number
749
- ensure_numeric Math.tanh number
778
+ def tanh angle
779
+ ensure_numeric Math.tanh angle.to_number
750
780
  end
751
781
 
752
782
  def true_constant
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # -*- mode: Ruby -*-
3
3
 
4
- # Copyright © 2013-2015, Christopher Mark Gore,
4
+ # Copyright © 2013-2016, Christopher Mark Gore,
5
5
  # Soli Deo Gloria,
6
6
  # All rights reserved.
7
7
  #
@@ -37,5 +37,8 @@
37
37
 
38
38
  module Teepee
39
39
  class ParserNode
40
+ def to_html
41
+ "" # You probably want to override this.
42
+ end
40
43
  end
41
44
  end
@@ -61,6 +61,10 @@ module Teepee
61
61
  @text
62
62
  end
63
63
 
64
+ def to_number
65
+ Float(to_html)
66
+ end
67
+
64
68
  class << self
65
69
  def full_match_regex
66
70
  self::FULL_MATCH_REGEX # Define this in a child class.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teepee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.11
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mark Gore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport