Class: Teepee::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/teepee/commander.rb

Direct Known Subclasses

ActionableCommander

Instance Method Summary collapse

Instance Method Details

#%(*numbers) ⇒ Object



177
178
179
# File 'lib/teepee/commander.rb', line 177

def % *numbers
  numbers.inject { |base, percent| base*percent/100.0 }
end

#*(*numbers) ⇒ Object



161
162
163
# File 'lib/teepee/commander.rb', line 161

def * *numbers
  ensure_numeric numbers.inject 1, :*
end

#**(*numbers) ⇒ Object



173
174
175
# File 'lib/teepee/commander.rb', line 173

def ** *numbers
  ensure_numeric numbers.reduce :**
end

#+(*numbers) ⇒ Object




149
150
151
# File 'lib/teepee/commander.rb', line 149

def + *numbers
  ensure_numeric numbers.inject 0, :+
end

#-(*numbers) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/teepee/commander.rb', line 153

def - *numbers
  if numbers.length == 1
    ensure_numeric -numbers.first
  else
    ensure_numeric numbers.reduce :-
  end
end

#/(*numbers) ⇒ Object



165
166
167
168
169
170
171
# File 'lib/teepee/commander.rb', line 165

def / *numbers
  if numbers.length == 1
    ensure_numeric 1 / numbers.first
  else
    ensure_numeric numbers.reduce :/
  end
end

#acos(number) ⇒ Object



193
194
195
# File 'lib/teepee/commander.rb', line 193

def acos number
  ensure_numeric Math.acos number
end

#acosh(number) ⇒ Object



197
198
199
# File 'lib/teepee/commander.rb', line 197

def acosh number
  ensure_numeric Math.acosh number
end

#add_percentage(*numbers) ⇒ Object



181
182
183
# File 'lib/teepee/commander.rb', line 181

def add_percentage *numbers
  numbers.inject {|base, percent| base * (1+percent/100.0) }
end

#asin(number) ⇒ Object



201
202
203
# File 'lib/teepee/commander.rb', line 201

def asin number
  ensure_numeric Math.asin number
end

#asinh(number) ⇒ Object



205
206
207
# File 'lib/teepee/commander.rb', line 205

def asinh number
  ensure_numeric Math.asinh number
end

#atan(number) ⇒ Object



209
210
211
# File 'lib/teepee/commander.rb', line 209

def atan number
  ensure_numeric Math.atan number
end

#atanh(number) ⇒ Object



213
214
215
# File 'lib/teepee/commander.rb', line 213

def atanh number
  ensure_numeric Math.atanh number
end

#b(expressions) ⇒ Object



217
218
219
# File 'lib/teepee/commander.rb', line 217

def b expressions
  html_tag :b, expressions
end

#backquoteObject



221
222
223
# File 'lib/teepee/commander.rb', line 221

def backquote
  "`"
end

#backslashObject



225
226
227
# File 'lib/teepee/commander.rb', line 225

def backslash
  "\\"
end

#big(expressions) ⇒ Object



229
230
231
# File 'lib/teepee/commander.rb', line 229

def big expressions
  html_tag :big, expressions
end

#bookmarks_folder_id(id) ⇒ Object



233
234
235
# File 'lib/teepee/commander.rb', line 233

def bookmarks_folder_id id
  id_command_handler id, :Folder, "folder", "folders", "folders/bookmarks_inline", "bookmarks"
end

#boolean_and(expressions) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/teepee/commander.rb', line 237

def boolean_and expressions
  if expressions.empty?
    true_constant
  elsif false_constant? expressions.first
    false_constant
  elsif true_constant? expressions.first or expressions.first.kind_of? WhitespaceToken
    boolean_and expressions[1..-1]
  else
    command_error "Not a boolean value #{expressions.first}"
  end
end

#boolean_nand(expressions) ⇒ Object



249
250
251
# File 'lib/teepee/commander.rb', line 249

def boolean_nand expressions
  boolean_not boolean_and expressions
end

#boolean_nor(expressions) ⇒ Object



253
254
255
# File 'lib/teepee/commander.rb', line 253

def boolean_nor expressions
  boolean_not boolean_or expressions
end

#boolean_not(expression) ⇒ Object



257
258
259
260
261
262
263
264
265
# File 'lib/teepee/commander.rb', line 257

def boolean_not expression
  if true_constant? expression
    false_constant
  elsif false_constant? expression
    true_constant
  else
    command_error "Not a boolean value"
  end
end

#boolean_or(expressions) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
# File 'lib/teepee/commander.rb', line 267

def boolean_or expressions
  if expressions.empty?
    false_constant
  elsif true_constant? expressions.first
    true_constant
  elsif false_constant? expressions.first or expressions.first.kind_of? WhitespaceToken
    boolean_or expressions[1..-1]
  else
    command_error "Not a boolean value"
  end
end

#boolean_xnor(expressions) ⇒ Object



279
280
281
# File 'lib/teepee/commander.rb', line 279

def boolean_xnor expressions
  boolean_not boolean_xor expressions
end

#boolean_xor(expressions) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/teepee/commander.rb', line 283

def boolean_xor expressions
  # There are two schools of thought as to what a multi-variable XOR is.
  # 1. Chained XORs, giving a parity check.
  # 2. 'Exclusively' one true for ALL inputs.
  # I'm going with the second: one and only one true, the rest false.
  # It seems therefore that the zero-argument version should be false then.
  if expressions.empty?
    false_constant
  else
    any_trues = false
    expressions.each do |expression|
      if true_constant? expression
        if any_trues
          return false_constant
        else
          any_trues = true
        end
      elsif false_constant? expression
        # do nothing
      elsif expression.kind_of? WhitespaceToken
        # do nothing
      else
        return command_error "Not a boolean value"
      end
    end
    return any_trues.to_s
  end
end

#brObject



312
313
314
# File 'lib/teepee/commander.rb', line 312

def br
  html_tag :br, nil
end

#command_error(message) ⇒ Object



46
47
48
# File 'lib/teepee/commander.rb', line 46

def command_error message
  %{<span style="color: red">[#{message}]</span>}
end

#command_not_yet_implemented(command) ⇒ Object



50
51
52
# File 'lib/teepee/commander.rb', line 50

def command_not_yet_implemented command
  command_error "The command #{command} is not yet implemented."
end

#cos(angle) ⇒ Object



316
317
318
# File 'lib/teepee/commander.rb', line 316

def cos angle
  ensure_numeric Math.cos angle
end

#cosh(number) ⇒ Object



320
321
322
# File 'lib/teepee/commander.rb', line 320

def cosh number
  ensure_numeric Math.cosh number
end

#degrees2radians(degrees) ⇒ Object



324
325
326
# File 'lib/teepee/commander.rb', line 324

def degrees2radians degrees
  ensure_numeric degrees * Math::PI / 180.0
end

#del(expressions) ⇒ Object



328
329
330
# File 'lib/teepee/commander.rb', line 328

def del expressions
  html_tag :del, expressions
end

#do_operator(expressions) ⇒ Object



332
333
334
# File 'lib/teepee/commander.rb', line 332

def do_operator expressions
  html_tag :span, expressions
end

#dollarObject



336
337
338
# File 'lib/teepee/commander.rb', line 336

def dollar
  "$"
end

#eObject



340
341
342
# File 'lib/teepee/commander.rb', line 340

def e
  Math::E
end

#ensure_boolean(boolean) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/teepee/commander.rb', line 68

def ensure_boolean boolean
  if boolean.to_s == "true" or boolean.to_s == "false"
    boolean
  else
    command_error "Non-boolean value."
  end
end

#ensure_numeric(number) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/teepee/commander.rb', line 58

def ensure_numeric number
  if number.kind_of? Complex
    command_error "Complex numbers are not yet supported."
  elsif not number.kind_of? Numeric
    command_error "Non-numeric result."
  else
    number
  end
end

#enumerate(expressions) ⇒ Object



354
355
356
# File 'lib/teepee/commander.rb', line 354

def enumerate expressions
  html_tag :ol, expressions
end

#enumerate_lowercase(expressions) ⇒ Object



366
367
368
# File 'lib/teepee/commander.rb', line 366

def enumerate_lowercase expressions
  html_tag :ol, expressions, {type: "a"}
end

#enumerate_numeric(expressions) ⇒ Object



358
359
360
# File 'lib/teepee/commander.rb', line 358

def enumerate_numeric expressions
  html_tag :ol, expressions, {type: "1"}
end

#enumerate_roman_lowercase(expressions) ⇒ Object



374
375
376
# File 'lib/teepee/commander.rb', line 374

def enumerate_roman_lowercase expressions
  html_tag :ol, expressions, {type: "i"}
end

#enumerate_roman_uppercase(expressions) ⇒ Object



370
371
372
# File 'lib/teepee/commander.rb', line 370

def enumerate_roman_uppercase expressions
  html_tag :ol, expressions, {type: "I"}
end

#enumerate_uppercase(expressions) ⇒ Object



362
363
364
# File 'lib/teepee/commander.rb', line 362

def enumerate_uppercase expressions
  html_tag :ol, expressions, {type: "A"}
end

#equal(*numbers) ⇒ Object



344
345
346
347
348
349
350
351
352
# File 'lib/teepee/commander.rb', line 344

def equal *numbers
  if numbers.empty?
    true_constant
  elsif numbers.length == 1
    true_constant
  else
    numbers[0] == numbers[1] and equal *numbers.rest
  end
end

#erf(number) ⇒ Object



378
379
380
# File 'lib/teepee/commander.rb', line 378

def erf number
  ensure_numeric Math.erf number
end

#erfc(number) ⇒ Object



382
383
384
# File 'lib/teepee/commander.rb', line 382

def erfc number
  ensure_numeric Math.erfc number
end

#false_constantObject



386
387
388
# File 'lib/teepee/commander.rb', line 386

def false_constant
  "false"
end

#false_constant?(expression) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/teepee/commander.rb', line 143

def false_constant? expression
  expression.to_s == "false"
end

#folder_id(id) ⇒ Object



390
391
392
# File 'lib/teepee/commander.rb', line 390

def folder_id id
  id_command_handler id, :Folder
end

#forum_id(id) ⇒ Object



394
395
396
# File 'lib/teepee/commander.rb', line 394

def forum_id id
  id_command_handler id, :Forum
end

#gamma(number) ⇒ Object



398
399
400
# File 'lib/teepee/commander.rb', line 398

def gamma number
  ensure_numeric Math.gamma number
end

#greater_than(*numbers) ⇒ Object



402
403
404
405
406
407
408
409
410
# File 'lib/teepee/commander.rb', line 402

def greater_than *numbers
  if numbers.empty?
    true_constant
  elsif numbers.length == 1
    true_constant
  else
    numbers[0] > numbers[1] and greater_than *numbers.rest
  end
end

#greater_than_or_equal(*numbers) ⇒ Object



412
413
414
415
416
417
418
419
420
# File 'lib/teepee/commander.rb', line 412

def greater_than_or_equal *numbers
  if numbers.empty?
    true_constant
  elsif numbers.length == 1
    true_constant
  else
    numbers[0] >= numbers[1] and greater_than_or_equal *numbers.rest
  end
end

#h1(expressions) ⇒ Object



422
423
424
# File 'lib/teepee/commander.rb', line 422

def h1 expressions
  html_tag :h1, expressions
end

#h2(expressions) ⇒ Object



426
427
428
# File 'lib/teepee/commander.rb', line 426

def h2 expressions
  html_tag :h2, expressions
end

#h3(expressions) ⇒ Object



430
431
432
# File 'lib/teepee/commander.rb', line 430

def h3 expressions
  html_tag :h3, expressions
end

#h4(expressions) ⇒ Object



434
435
436
# File 'lib/teepee/commander.rb', line 434

def h4 expressions
  html_tag :h4, expressions
end

#h5(expressions) ⇒ Object



438
439
440
# File 'lib/teepee/commander.rb', line 438

def h5 expressions
  html_tag :h5, expressions
end

#h6(expressions) ⇒ Object



442
443
444
# File 'lib/teepee/commander.rb', line 442

def h6 expressions
  html_tag :h6, expressions
end

#html_tag(tag, expressions, attribs = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/teepee/commander.rb', line 76

def html_tag tag, expressions, attribs=nil
  opening_tag = if attribs
                  attribs_string = attribs.map {|k,v| %{#{k}="#{v}"}}.join " "
                  if expressions.nil?
                    "<#{tag} #{attribs_string}/>"
                  else
                    "<#{tag} #{attribs_string}>"
                  end
                else
                  if expressions.nil?
                    "<#{tag}/>"
                  else
                    "<#{tag}>"
                  end
                end
  if expressions.nil?
    opening_tag
  else
    opening_tag + expressions.map(&:to_html).join.strip + "</#{tag}>"
  end
end

#hypot(numbers) ⇒ Object



503
504
505
# File 'lib/teepee/commander.rb', line 503

def hypot numbers
  ensure_numeric Math.sqrt numbers.map {|n| n**2}
end

#iObject



446
447
448
# File 'lib/teepee/commander.rb', line 446

def i
  command_error "Complex numbers are not yet supported."
end

#id_command_handler(id, klass, singular = klass.to_s.camelcase_to_snakecase, plural = singular.pluralize, partial = "#{plural}/inline", view = "") ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/teepee/commander.rb', line 102

def id_command_handler(id,
                       klass,
                       singular = klass.to_s.camelcase_to_snakecase,
                       plural = singular.pluralize,
                       partial = "#{plural}/inline",
                       view="")
  if not id
    command_error "#{singular}_id: error: no #{singular} ID specified"
  elsif not id.to_s =~ /\A[0-9]+\z/
    command_error "#{singular}_id: error: invalid #{singular} ID specified"
  else
    tb_href "#{plural}/#{id.to_s}/#{view}", "#{klass.to_s} ##{id.to_s}"
  end
end

#if_operator(expressions) ⇒ Object



450
451
452
453
454
455
456
457
458
# File 'lib/teepee/commander.rb', line 450

def if_operator expressions
  expressions = strip expressions
  conditional, _, true_clause, _, false_clause = expressions
  if true_constant? conditional
    true_clause.to_html
  elsif false_clause
    false_clause.to_html
  end
end

#image(expressions) ⇒ Object



460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/teepee/commander.rb', line 460

def image expressions
  expressions = strip expressions
  uri, *alt_text = expressions
  uri = ERB::Util.html_escape uri.to_s
  if not valid_uri? uri
    command_error "Not a valid URI for the image."
  else
    if alt_text.empty?
      html_tag :img, nil, {src: uri}
    else
      html_tag :img, nil, {src: uri, alt: alt_text.map(&:to_s).join.strip}
    end
  end
end

#it(expressions) ⇒ Object



475
476
477
# File 'lib/teepee/commander.rb', line 475

def it expressions
  html_tag :i, expressions
end

#item(expressions) ⇒ Object



479
480
481
# File 'lib/teepee/commander.rb', line 479

def item expressions
  html_tag :li, expressions
end

#itemize(expressions) ⇒ Object



483
484
485
# File 'lib/teepee/commander.rb', line 483

def itemize expressions
  html_tag :ul, expressions
end

#itemize_circle(expressions) ⇒ Object



491
492
493
# File 'lib/teepee/commander.rb', line 491

def itemize_circle expressions
  html_tag :ul, expressions, {style: "list-style-type:circle"}
end

#itemize_disc(expressions) ⇒ Object



487
488
489
# File 'lib/teepee/commander.rb', line 487

def itemize_disc expressions
  html_tag :ul, expressions, {style: "list-style-type:disc"}
end

#itemize_none(expressions) ⇒ Object



499
500
501
# File 'lib/teepee/commander.rb', line 499

def itemize_none expressions
  html_tag :ul, expressions, {style: "list-style-type:none"}
end

#itemize_square(expressions) ⇒ Object



495
496
497
# File 'lib/teepee/commander.rb', line 495

def itemize_square expressions
  html_tag :ul, expressions, {style: "list-style-type:square"}
end

#keyword_id(id) ⇒ Object



507
508
509
# File 'lib/teepee/commander.rb', line 507

def keyword_id id
  id_command_handler id, :Keyword
end

#ld(n) ⇒ Object



511
512
513
# File 'lib/teepee/commander.rb', line 511

def ld n
  ensure_numeric Math.log2 n
end

#ldexp(fraction, exponent) ⇒ Object



515
516
517
# File 'lib/teepee/commander.rb', line 515

def ldexp fraction, exponent
  ensure_numeric Math.ldexp fraction, exponent
end

#left_braceObject



519
520
521
# File 'lib/teepee/commander.rb', line 519

def left_brace
  "{"
end

#left_bracketObject



523
524
525
# File 'lib/teepee/commander.rb', line 523

def left_bracket
  "["
end

#left_strip(expressions) ⇒ Object



117
118
119
120
121
122
# File 'lib/teepee/commander.rb', line 117

def left_strip expressions
  while expressions.first.kind_of? WhitespaceToken
    expressions.shift
  end
  expressions
end

#less_than(*numbers) ⇒ Object



527
528
529
530
531
532
533
534
535
# File 'lib/teepee/commander.rb', line 527

def less_than *numbers
  if numbers.empty?
    true_constant
  elsif numbers.length == 1
    true_constant
  else
    numbers[0] < numbers[1] and less_than *numbers.rest
  end
end

#less_than_or_equal(*numbers) ⇒ Object



537
538
539
540
541
542
543
544
545
# File 'lib/teepee/commander.rb', line 537

def less_than_or_equal *numbers
  if numbers.empty?
    true_constant
  elsif numbers.length == 1
    true_constant
  else
    numbers[0] <= numbers[1] and less_than_or_equal *numbers.rest
  end
end

#lgamma(n) ⇒ Object



547
548
549
# File 'lib/teepee/commander.rb', line 547

def lgamma n
  ensure_numeric Math::lgamma(n).first
end


551
552
553
554
555
556
557
558
559
560
561
# File 'lib/teepee/commander.rb', line 551

def link expressions
  expressions = strip expressions
  uri, *desc = expressions
  uri = ERB::Util.html_escape uri.to_s
  if not valid_uri? uri
    command_error "Not a valid URI."
  else
    desc = [uri] if desc.empty?
    html_tag :a, desc, {href: uri}
  end
end


563
564
565
# File 'lib/teepee/commander.rb', line 563

def link_id id
  id_command_handler id, :Link
end

#ln(number) ⇒ Object



567
568
569
# File 'lib/teepee/commander.rb', line 567

def ln number
  ensure_numeric Math.log number
end

#log(base, number) ⇒ Object



571
572
573
574
575
576
577
578
# File 'lib/teepee/commander.rb', line 571

def log base, number
  if number.nil?
    number, base = base, number
    ensure_numeric Math.log10 number # default to log base 10
  else
    ensure_numeric Math.log number, base
  end
end

#log10(number) ⇒ Object



580
581
582
# File 'lib/teepee/commander.rb', line 580

def log10 number
  ensure_numeric Math.log10 number
end

#mailto(email_address) ⇒ Object



584
585
586
587
588
589
590
591
# File 'lib/teepee/commander.rb', line 584

def mailto email_address
  email_address = email_address.to_s
  if valid_email_address? email_address
    html_tag :a, [email_address], {href: "mailto:#{email_address}"}
  else
    command_error "I'm not sure that's a valid email address."
  end
end

#mod(*numbers) ⇒ Object



593
594
595
# File 'lib/teepee/commander.rb', line 593

def mod *numbers
  ensure_numeric numbers.reduce :%
end

#nbsp(count) ⇒ Object



597
598
599
600
# File 'lib/teepee/commander.rb', line 597

def nbsp count
  count = 1 unless count and count.kind_of? Numeric and count > 0
  "&nbsp;" * count
end

#not_equal(*numbers) ⇒ Object



602
603
604
605
606
607
608
609
610
# File 'lib/teepee/commander.rb', line 602

def not_equal *numbers
  if numbers.empty?
    true_constant
  elsif numbers.length == 1
    true_constant
  else
    numbers[0] != numbers[1] and equal *numbers.rest
  end
end

#note_id(id) ⇒ Object



612
613
614
# File 'lib/teepee/commander.rb', line 612

def note_id id
  id_command_handler id, :Note
end

#numeric?(*numbers) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/teepee/commander.rb', line 54

def numeric? *numbers
  numbers.all? {|number| number.kind_of? Numeric}
end

#percent_total(*numbers) ⇒ Object



189
190
191
# File 'lib/teepee/commander.rb', line 189

def percent_total *numbers
  numbers.inject {|total, part| Float(part)/Float(total)*100.0 }
end

#piObject



616
617
618
# File 'lib/teepee/commander.rb', line 616

def pi
  Math::PI
end

#pipeObject



620
621
622
# File 'lib/teepee/commander.rb', line 620

def pipe
  "|"
end

#radians2degrees(radians) ⇒ Object



624
625
626
# File 'lib/teepee/commander.rb', line 624

def radians2degrees radians
  ensure_numeric(radians * 180.0 / Math::PI)
end

#right_braceObject



628
629
630
# File 'lib/teepee/commander.rb', line 628

def right_brace
  "}"
end

#right_bracketObject



632
633
634
# File 'lib/teepee/commander.rb', line 632

def right_bracket
  "]"
end

#right_strip(expressions) ⇒ Object



124
125
126
127
128
129
# File 'lib/teepee/commander.rb', line 124

def right_strip expressions
  while expressions.last.kind_of? WhitespaceToken
    expressions.pop
  end
  expressions
end

#sin(angle) ⇒ Object



636
637
638
# File 'lib/teepee/commander.rb', line 636

def sin angle
  ensure_numeric Math.sin angle
end

#sinh(number) ⇒ Object



640
641
642
# File 'lib/teepee/commander.rb', line 640

def sinh number
  ensure_numeric Math.sinh number
end

#small(expressions) ⇒ Object



644
645
646
# File 'lib/teepee/commander.rb', line 644

def small expressions
  html_tag :small, expressions
end

#spaceObject



656
657
658
# File 'lib/teepee/commander.rb', line 656

def space
  " "
end

#sqrt(number) ⇒ Object



652
653
654
# File 'lib/teepee/commander.rb', line 652

def sqrt number
  ensure_numeric Math.sqrt number
end

#squiggleObject



648
649
650
# File 'lib/teepee/commander.rb', line 648

def squiggle
  "~"
end

#strip(expressions) ⇒ Object



131
132
133
# File 'lib/teepee/commander.rb', line 131

def strip expressions
  left_strip right_strip expressions
end

#sub(expressions) ⇒ Object



660
661
662
# File 'lib/teepee/commander.rb', line 660

def sub expressions
  html_tag :sub, expressions
end

#subtract_percentage(*numbers) ⇒ Object



185
186
187
# File 'lib/teepee/commander.rb', line 185

def subtract_percentage *numbers
  numbers.inject {|base, percent| base * (1-percent/100.0) }
end

#sup(expressions) ⇒ Object



664
665
666
# File 'lib/teepee/commander.rb', line 664

def sup expressions
  html_tag :sup, expressions
end

#table(expressions) ⇒ Object



668
669
670
# File 'lib/teepee/commander.rb', line 668

def table expressions
  html_tag :table, expressions
end

#table_data(expressions) ⇒ Object



672
673
674
# File 'lib/teepee/commander.rb', line 672

def table_data expressions
  html_tag :td, expressions
end

#table_header(expressions) ⇒ Object



676
677
678
# File 'lib/teepee/commander.rb', line 676

def table_header expressions
  html_tag :th, expressions
end

#table_row(expressions) ⇒ Object



680
681
682
# File 'lib/teepee/commander.rb', line 680

def table_row expressions
  html_tag :tr, expressions
end

#tag_id(id) ⇒ Object



684
685
686
# File 'lib/teepee/commander.rb', line 684

def tag_id id
  id_command_handler id, :Tag
end

#tan(angle) ⇒ Object



688
689
690
# File 'lib/teepee/commander.rb', line 688

def tan angle
  ensure_numeric Math.tan angle
end

#tanh(number) ⇒ Object



692
693
694
# File 'lib/teepee/commander.rb', line 692

def tanh number
  ensure_numeric Math.tanh number
end

#tb_href(target, string) ⇒ Object



98
99
100
# File 'lib/teepee/commander.rb', line 98

def tb_href target, string
  %{<a href="#{TB_COM}/#{target}">#{string}</a>}
end

#true_constantObject



696
697
698
# File 'lib/teepee/commander.rb', line 696

def true_constant
  "true"
end

#true_constant?(expression) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/teepee/commander.rb', line 139

def true_constant? expression
  expression.to_s == "true"
end

#tt(expressions) ⇒ Object



700
701
702
# File 'lib/teepee/commander.rb', line 700

def tt expressions
  html_tag :tt, expressions
end

#u(expressions) ⇒ Object



704
705
706
# File 'lib/teepee/commander.rb', line 704

def u expressions
  html_tag :u, expressions
end

#unless_operator(expressions) ⇒ Object



708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/teepee/commander.rb', line 708

def unless_operator expressions
  expressions = strip expressions
  conditional = expressions.first
  expressions = strip expressions.rest
  if false_constant? conditional
    if expressions.length <= 1
      expressions.first
    else
      do_operator expressions
    end
  end
end

#user(user) ⇒ Object



721
722
723
724
725
726
727
# File 'lib/teepee/commander.rb', line 721

def user user
  if not user
    command_error "user: error: no user specified"
  else
    tb_href "users/#{user}", user.to_s
  end
end

#valid_email_address?(email_address) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/teepee/commander.rb', line 135

def valid_email_address? email_address
  email_address =~ /\A[[:graph:]]+@[\w.]+\z/
end

#valid_uri?(uri) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/teepee/commander.rb', line 40

def valid_uri? uri
  (!! (u = URI.parse(uri))) and not u.scheme.nil?
rescue URI::InvalidURIError
  false
end

#when_operator(expressions) ⇒ Object



729
730
731
732
733
734
735
736
737
738
739
740
# File 'lib/teepee/commander.rb', line 729

def when_operator expressions
  expressions = strip expressions
  conditional = expressions.first
  expressions = strip expressions.rest
  if true_constant? conditional
    if expressions.length <= 1
      expressions.first
    else
      do_operator expressions
    end
  end
end