Class: Teepee::Commander
- Inherits:
-
Object
- Object
- Teepee::Commander
- Defined in:
- lib/teepee/commander.rb
Direct Known Subclasses
Instance Method Summary collapse
- #%(*numbers) ⇒ Object
- #*(*numbers) ⇒ Object
- #**(*numbers) ⇒ Object
-
#+(*numbers) ⇒ Object
—————————————————————————-.
- #-(*numbers) ⇒ Object
- #/(*numbers) ⇒ Object
- #acos(number) ⇒ Object
- #acosh(number) ⇒ Object
- #add_percentage(*numbers) ⇒ Object
- #asin(number) ⇒ Object
- #asinh(number) ⇒ Object
- #atan(number) ⇒ Object
- #atanh(number) ⇒ Object
- #b(expressions) ⇒ Object
- #backquote ⇒ Object
- #backslash ⇒ Object
- #big(expressions) ⇒ Object
- #bookmarks_folder_id(id) ⇒ Object
- #boolean_and(expressions) ⇒ Object
- #boolean_nand(expressions) ⇒ Object
- #boolean_nor(expressions) ⇒ Object
- #boolean_not(expression) ⇒ Object
- #boolean_or(expressions) ⇒ Object
- #boolean_xnor(expressions) ⇒ Object
- #boolean_xor(expressions) ⇒ Object
- #br ⇒ Object
- #case_operator(expressions) ⇒ Object
- #ceiling(number) ⇒ Object
- #command_error(message) ⇒ Object
- #command_not_yet_implemented(command) ⇒ Object
- #comment(expressions) ⇒ Object
- #cond_operator(expressions) ⇒ Object
- #cos(angle) ⇒ Object
- #cosh(number) ⇒ Object
- #degrees2radians(degrees) ⇒ Object
- #del(expressions) ⇒ Object
- #dollar ⇒ Object
- #e ⇒ Object
- #ensure_boolean(boolean) ⇒ Object
- #ensure_numeric(number) ⇒ Object
- #enumerate(expressions) ⇒ Object
- #enumerate_lowercase(expressions) ⇒ Object
- #enumerate_numeric(expressions) ⇒ Object
- #enumerate_roman_lowercase(expressions) ⇒ Object
- #enumerate_roman_uppercase(expressions) ⇒ Object
- #enumerate_uppercase(expressions) ⇒ Object
- #equal(*expressions) ⇒ Object
- #erf(number) ⇒ Object
- #erfc(number) ⇒ Object
- #false_constant ⇒ Object
- #false_constant?(expression) ⇒ Boolean
- #floor(number) ⇒ Object
- #folder_id(id) ⇒ Object
- #forum_id(id) ⇒ Object
- #gamma(number) ⇒ Object
- #greater_than(*numbers) ⇒ Object
- #greater_than_or_equal(*numbers) ⇒ Object
- #h1(expressions) ⇒ Object
- #h2(expressions) ⇒ Object
- #h3(expressions) ⇒ Object
- #h4(expressions) ⇒ Object
- #h5(expressions) ⇒ Object
- #h6(expressions) ⇒ Object
- #html_tag(tag, expressions, attribs = nil) ⇒ Object
- #hypot(numbers) ⇒ Object
- #i ⇒ Object
- #id_command_handler(id, klass, singular = klass.to_s.camelcase_to_snakecase, plural = singular.pluralize, partial = "#{plural}/inline", view = "") ⇒ Object
- #if_operator(expressions) ⇒ Object
- #image(expressions) ⇒ Object
- #it(expressions) ⇒ Object
- #item(expressions) ⇒ Object
- #itemize(expressions) ⇒ Object
- #itemize_circle(expressions) ⇒ Object
- #itemize_disc(expressions) ⇒ Object
- #itemize_none(expressions) ⇒ Object
- #itemize_square(expressions) ⇒ Object
- #keyword_id(id) ⇒ Object
- #ld(n) ⇒ Object
- #ldexp(fraction, exponent) ⇒ Object
- #left_brace ⇒ Object
- #left_bracket ⇒ Object
- #left_strip(expressions) ⇒ Object
- #less_than(*numbers) ⇒ Object
- #less_than_or_equal(*numbers) ⇒ Object
- #lgamma(n) ⇒ Object
- #link(expressions) ⇒ Object
- #link_id(id) ⇒ Object
- #ln(number) ⇒ Object
- #log(base, number) ⇒ Object
- #log10(number) ⇒ Object
- #mailto(email_address) ⇒ Object
- #mod(*numbers) ⇒ Object
- #nbsp(count) ⇒ Object
- #not_equal(*numbers) ⇒ Object
- #note_id(id) ⇒ Object
- #numeric?(*numbers) ⇒ Boolean
- #percent_total(*numbers) ⇒ Object
- #pi ⇒ Object
- #pipe ⇒ Object
- #pipe?(expression) ⇒ Boolean
- #prog1_operator(expressions) ⇒ Object
- #progn_operator(expressions) ⇒ Object
- #radians2degrees(radians) ⇒ Object
- #right_brace ⇒ Object
- #right_bracket ⇒ Object
- #right_strip(expressions) ⇒ Object
- #round(number, precision = nil, *_) ⇒ Object
- #sin(angle) ⇒ Object
- #sinh(number) ⇒ Object
- #small(expressions) ⇒ Object
- #space ⇒ Object
- #span_operator(expressions) ⇒ Object
- #sqrt(number) ⇒ Object
- #squiggle ⇒ Object
- #strip(expressions) ⇒ Object
- #sub(expressions) ⇒ Object
- #subtract_percentage(*numbers) ⇒ Object
- #sup(expressions) ⇒ Object
- #table(expressions) ⇒ Object
- #table_data(expressions) ⇒ Object
- #table_header(expressions) ⇒ Object
- #table_row(expressions) ⇒ Object
- #tag_id(id) ⇒ Object
- #tan(angle) ⇒ Object
- #tanh(number) ⇒ Object
- #tb_href(target, string) ⇒ Object
- #true_constant ⇒ Object
- #true_constant?(expression) ⇒ Boolean
- #tt(expressions) ⇒ Object
- #u(expressions) ⇒ Object
- #unless_operator(expressions) ⇒ Object
- #user(user) ⇒ Object
- #valid_email_address?(email_address) ⇒ Boolean
- #valid_uri?(uri) ⇒ Boolean
- #when_operator(expressions) ⇒ Object
Instance Method Details
#%(*numbers) ⇒ Object
181 182 183 |
# File 'lib/teepee/commander.rb', line 181 def % *numbers numbers.inject { |base, percent| base*percent/100.0 } end |
#*(*numbers) ⇒ Object
165 166 167 |
# File 'lib/teepee/commander.rb', line 165 def * *numbers ensure_numeric numbers.inject 1, :* end |
#**(*numbers) ⇒ Object
177 178 179 |
# File 'lib/teepee/commander.rb', line 177 def ** *numbers ensure_numeric numbers.reduce :** end |
#+(*numbers) ⇒ Object
153 154 155 |
# File 'lib/teepee/commander.rb', line 153 def + *numbers ensure_numeric numbers.inject 0, :+ end |
#-(*numbers) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/teepee/commander.rb', line 157 def - *numbers if numbers.length == 1 ensure_numeric -numbers.first else ensure_numeric numbers.reduce :- end end |
#/(*numbers) ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/teepee/commander.rb', line 169 def / *numbers if numbers.length == 1 ensure_numeric 1 / numbers.first else ensure_numeric numbers.reduce :/ end end |
#acos(number) ⇒ Object
197 198 199 |
# File 'lib/teepee/commander.rb', line 197 def acos number ensure_numeric Math.acos number end |
#acosh(number) ⇒ Object
201 202 203 |
# File 'lib/teepee/commander.rb', line 201 def acosh number ensure_numeric Math.acosh number end |
#add_percentage(*numbers) ⇒ Object
185 186 187 |
# File 'lib/teepee/commander.rb', line 185 def add_percentage *numbers numbers.inject {|base, percent| base * (1+percent/100.0) } end |
#asin(number) ⇒ Object
205 206 207 |
# File 'lib/teepee/commander.rb', line 205 def asin number ensure_numeric Math.asin number end |
#asinh(number) ⇒ Object
209 210 211 |
# File 'lib/teepee/commander.rb', line 209 def asinh number ensure_numeric Math.asinh number end |
#atan(number) ⇒ Object
213 214 215 |
# File 'lib/teepee/commander.rb', line 213 def atan number ensure_numeric Math.atan number end |
#atanh(number) ⇒ Object
217 218 219 |
# File 'lib/teepee/commander.rb', line 217 def atanh number ensure_numeric Math.atanh number end |
#b(expressions) ⇒ Object
221 222 223 |
# File 'lib/teepee/commander.rb', line 221 def b expressions html_tag :b, expressions end |
#backquote ⇒ Object
225 226 227 |
# File 'lib/teepee/commander.rb', line 225 def backquote "`" end |
#backslash ⇒ Object
229 230 231 |
# File 'lib/teepee/commander.rb', line 229 def backslash "\\" end |
#big(expressions) ⇒ Object
233 234 235 |
# File 'lib/teepee/commander.rb', line 233 def big expressions html_tag :big, expressions end |
#bookmarks_folder_id(id) ⇒ Object
237 238 239 |
# File 'lib/teepee/commander.rb', line 237 def bookmarks_folder_id id id_command_handler id, :Folder, "folder", "folders", "folders/bookmarks_inline", "bookmarks" end |
#boolean_and(expressions) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/teepee/commander.rb', line 241 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
253 254 255 |
# File 'lib/teepee/commander.rb', line 253 def boolean_nand expressions boolean_not boolean_and expressions end |
#boolean_nor(expressions) ⇒ Object
257 258 259 |
# File 'lib/teepee/commander.rb', line 257 def boolean_nor expressions boolean_not boolean_or expressions end |
#boolean_not(expression) ⇒ Object
261 262 263 264 265 266 267 268 269 |
# File 'lib/teepee/commander.rb', line 261 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
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/teepee/commander.rb', line 271 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
283 284 285 |
# File 'lib/teepee/commander.rb', line 283 def boolean_xnor expressions boolean_not boolean_xor expressions end |
#boolean_xor(expressions) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/teepee/commander.rb', line 287 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 |
#br ⇒ Object
316 317 318 |
# File 'lib/teepee/commander.rb', line 316 def br html_tag :br, nil end |
#case_operator(expressions) ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/teepee/commander.rb', line 320 def case_operator expressions value, _, *rest = strip expressions if value and not rest.empty? def cond_helper value, expressions test_value, _, form, *rest = strip expressions if equal value, test_value form elsif not rest.empty? cond_helper value, rest end end cond_helper value, rest end end |
#ceiling(number) ⇒ Object
335 336 337 |
# File 'lib/teepee/commander.rb', line 335 def ceiling number ensure_numeric number.ceil end |
#command_error(message) ⇒ Object
46 47 48 |
# File 'lib/teepee/commander.rb', line 46 def command_error %{<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 |
#comment(expressions) ⇒ Object
339 340 341 |
# File 'lib/teepee/commander.rb', line 339 def comment expressions nil end |
#cond_operator(expressions) ⇒ Object
343 344 345 346 347 348 349 350 |
# File 'lib/teepee/commander.rb', line 343 def cond_operator expressions conditional, _, form, *rest = strip expressions if true_constant? conditional form elsif not rest.empty? cond_operator rest end end |
#cos(angle) ⇒ Object
352 353 354 |
# File 'lib/teepee/commander.rb', line 352 def cos angle ensure_numeric Math.cos angle end |
#cosh(number) ⇒ Object
356 357 358 |
# File 'lib/teepee/commander.rb', line 356 def cosh number ensure_numeric Math.cosh number end |
#degrees2radians(degrees) ⇒ Object
360 361 362 |
# File 'lib/teepee/commander.rb', line 360 def degrees2radians degrees ensure_numeric degrees * Math::PI / 180.0 end |
#del(expressions) ⇒ Object
364 365 366 |
# File 'lib/teepee/commander.rb', line 364 def del expressions html_tag :del, expressions end |
#dollar ⇒ Object
368 369 370 |
# File 'lib/teepee/commander.rb', line 368 def dollar "$" end |
#e ⇒ Object
372 373 374 |
# File 'lib/teepee/commander.rb', line 372 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
386 387 388 |
# File 'lib/teepee/commander.rb', line 386 def enumerate expressions html_tag :ol, expressions end |
#enumerate_lowercase(expressions) ⇒ Object
398 399 400 |
# File 'lib/teepee/commander.rb', line 398 def enumerate_lowercase expressions html_tag :ol, expressions, {type: "a"} end |
#enumerate_numeric(expressions) ⇒ Object
390 391 392 |
# File 'lib/teepee/commander.rb', line 390 def enumerate_numeric expressions html_tag :ol, expressions, {type: "1"} end |
#enumerate_roman_lowercase(expressions) ⇒ Object
406 407 408 |
# File 'lib/teepee/commander.rb', line 406 def enumerate_roman_lowercase expressions html_tag :ol, expressions, {type: "i"} end |
#enumerate_roman_uppercase(expressions) ⇒ Object
402 403 404 |
# File 'lib/teepee/commander.rb', line 402 def enumerate_roman_uppercase expressions html_tag :ol, expressions, {type: "I"} end |
#enumerate_uppercase(expressions) ⇒ Object
394 395 396 |
# File 'lib/teepee/commander.rb', line 394 def enumerate_uppercase expressions html_tag :ol, expressions, {type: "A"} end |
#equal(*expressions) ⇒ Object
376 377 378 379 380 381 382 383 384 |
# File 'lib/teepee/commander.rb', line 376 def equal *expressions if expressions.empty? true_constant elsif expressions.length == 1 true_constant else expressions[0].to_s == expressions[1].to_s and equal *expressions.rest end end |
#erf(number) ⇒ Object
410 411 412 |
# File 'lib/teepee/commander.rb', line 410 def erf number ensure_numeric Math.erf number end |
#erfc(number) ⇒ Object
414 415 416 |
# File 'lib/teepee/commander.rb', line 414 def erfc number ensure_numeric Math.erfc number end |
#false_constant ⇒ Object
418 419 420 |
# File 'lib/teepee/commander.rb', line 418 def false_constant "false" end |
#false_constant?(expression) ⇒ Boolean
143 144 145 |
# File 'lib/teepee/commander.rb', line 143 def false_constant? expression expression.to_s == "false" end |
#floor(number) ⇒ Object
422 423 424 |
# File 'lib/teepee/commander.rb', line 422 def floor number ensure_numeric number.floor end |
#folder_id(id) ⇒ Object
426 427 428 |
# File 'lib/teepee/commander.rb', line 426 def folder_id id id_command_handler id, :Folder end |
#forum_id(id) ⇒ Object
430 431 432 |
# File 'lib/teepee/commander.rb', line 430 def forum_id id id_command_handler id, :Forum end |
#gamma(number) ⇒ Object
434 435 436 |
# File 'lib/teepee/commander.rb', line 434 def gamma number ensure_numeric Math.gamma number end |
#greater_than(*numbers) ⇒ Object
438 439 440 441 442 443 444 445 446 |
# File 'lib/teepee/commander.rb', line 438 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
448 449 450 451 452 453 454 455 456 |
# File 'lib/teepee/commander.rb', line 448 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
458 459 460 |
# File 'lib/teepee/commander.rb', line 458 def h1 expressions html_tag :h1, expressions end |
#h2(expressions) ⇒ Object
462 463 464 |
# File 'lib/teepee/commander.rb', line 462 def h2 expressions html_tag :h2, expressions end |
#h3(expressions) ⇒ Object
466 467 468 |
# File 'lib/teepee/commander.rb', line 466 def h3 expressions html_tag :h3, expressions end |
#h4(expressions) ⇒ Object
470 471 472 |
# File 'lib/teepee/commander.rb', line 470 def h4 expressions html_tag :h4, expressions end |
#h5(expressions) ⇒ Object
474 475 476 |
# File 'lib/teepee/commander.rb', line 474 def h5 expressions html_tag :h5, expressions end |
#h6(expressions) ⇒ Object
478 479 480 |
# File 'lib/teepee/commander.rb', line 478 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
539 540 541 |
# File 'lib/teepee/commander.rb', line 539 def hypot numbers ensure_numeric Math.sqrt numbers.map {|n| n**2} end |
#i ⇒ Object
482 483 484 |
# File 'lib/teepee/commander.rb', line 482 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
486 487 488 489 490 491 492 493 494 |
# File 'lib/teepee/commander.rb', line 486 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
496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/teepee/commander.rb', line 496 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
511 512 513 |
# File 'lib/teepee/commander.rb', line 511 def it expressions html_tag :i, expressions end |
#item(expressions) ⇒ Object
515 516 517 |
# File 'lib/teepee/commander.rb', line 515 def item expressions html_tag :li, expressions end |
#itemize(expressions) ⇒ Object
519 520 521 |
# File 'lib/teepee/commander.rb', line 519 def itemize expressions html_tag :ul, expressions end |
#itemize_circle(expressions) ⇒ Object
527 528 529 |
# File 'lib/teepee/commander.rb', line 527 def itemize_circle expressions html_tag :ul, expressions, {style: "list-style-type:circle"} end |
#itemize_disc(expressions) ⇒ Object
523 524 525 |
# File 'lib/teepee/commander.rb', line 523 def itemize_disc expressions html_tag :ul, expressions, {style: "list-style-type:disc"} end |
#itemize_none(expressions) ⇒ Object
535 536 537 |
# File 'lib/teepee/commander.rb', line 535 def itemize_none expressions html_tag :ul, expressions, {style: "list-style-type:none"} end |
#itemize_square(expressions) ⇒ Object
531 532 533 |
# File 'lib/teepee/commander.rb', line 531 def itemize_square expressions html_tag :ul, expressions, {style: "list-style-type:square"} end |
#keyword_id(id) ⇒ Object
543 544 545 |
# File 'lib/teepee/commander.rb', line 543 def keyword_id id id_command_handler id, :Keyword end |
#ld(n) ⇒ Object
547 548 549 |
# File 'lib/teepee/commander.rb', line 547 def ld n ensure_numeric Math.log2 n end |
#ldexp(fraction, exponent) ⇒ Object
551 552 553 |
# File 'lib/teepee/commander.rb', line 551 def ldexp fraction, exponent ensure_numeric Math.ldexp fraction, exponent end |
#left_brace ⇒ Object
555 556 557 |
# File 'lib/teepee/commander.rb', line 555 def left_brace "{" end |
#left_bracket ⇒ Object
559 560 561 |
# File 'lib/teepee/commander.rb', line 559 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
563 564 565 566 567 568 569 570 571 |
# File 'lib/teepee/commander.rb', line 563 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
573 574 575 576 577 578 579 580 581 |
# File 'lib/teepee/commander.rb', line 573 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
583 584 585 |
# File 'lib/teepee/commander.rb', line 583 def lgamma n ensure_numeric Math::lgamma(n).first end |
#link(expressions) ⇒ Object
587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/teepee/commander.rb', line 587 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 |
#link_id(id) ⇒ Object
599 600 601 |
# File 'lib/teepee/commander.rb', line 599 def link_id id id_command_handler id, :Link end |
#ln(number) ⇒ Object
603 604 605 |
# File 'lib/teepee/commander.rb', line 603 def ln number ensure_numeric Math.log number end |
#log(base, number) ⇒ Object
607 608 609 610 611 612 613 614 |
# File 'lib/teepee/commander.rb', line 607 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
616 617 618 |
# File 'lib/teepee/commander.rb', line 616 def log10 number ensure_numeric Math.log10 number end |
#mailto(email_address) ⇒ Object
620 621 622 623 624 625 626 627 |
# File 'lib/teepee/commander.rb', line 620 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
629 630 631 |
# File 'lib/teepee/commander.rb', line 629 def mod *numbers ensure_numeric numbers.reduce :% end |
#nbsp(count) ⇒ Object
633 634 635 636 |
# File 'lib/teepee/commander.rb', line 633 def nbsp count count = 1 unless count and count.kind_of? Numeric and count > 0 " " * count end |
#not_equal(*numbers) ⇒ Object
638 639 640 641 642 643 644 645 646 |
# File 'lib/teepee/commander.rb', line 638 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
648 649 650 |
# File 'lib/teepee/commander.rb', line 648 def note_id id id_command_handler id, :Note end |
#numeric?(*numbers) ⇒ 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
193 194 195 |
# File 'lib/teepee/commander.rb', line 193 def percent_total *numbers numbers.inject {|total, part| Float(part)/Float(total)*100.0 } end |
#pi ⇒ Object
652 653 654 |
# File 'lib/teepee/commander.rb', line 652 def pi Math::PI end |
#pipe ⇒ Object
656 657 658 |
# File 'lib/teepee/commander.rb', line 656 def pipe "|" end |
#pipe?(expression) ⇒ Boolean
147 148 149 |
# File 'lib/teepee/commander.rb', line 147 def pipe? expression expression.is_a? PipeToken end |
#prog1_operator(expressions) ⇒ Object
660 661 662 |
# File 'lib/teepee/commander.rb', line 660 def prog1_operator expressions expressions.first end |
#progn_operator(expressions) ⇒ Object
664 665 666 |
# File 'lib/teepee/commander.rb', line 664 def progn_operator expressions expressions.last end |
#radians2degrees(radians) ⇒ Object
668 669 670 |
# File 'lib/teepee/commander.rb', line 668 def radians2degrees radians ensure_numeric(radians * 180.0 / Math::PI) end |
#right_brace ⇒ Object
672 673 674 |
# File 'lib/teepee/commander.rb', line 672 def right_brace "}" end |
#right_bracket ⇒ Object
676 677 678 |
# File 'lib/teepee/commander.rb', line 676 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 |
#round(number, precision = nil, *_) ⇒ Object
680 681 682 683 684 685 686 |
# File 'lib/teepee/commander.rb', line 680 def round number, precision = nil, *_ if precision.nil? ensure_numeric number.round else ensure_numeric number.round precision end end |
#sin(angle) ⇒ Object
688 689 690 |
# File 'lib/teepee/commander.rb', line 688 def sin angle ensure_numeric Math.sin angle end |
#sinh(number) ⇒ Object
692 693 694 |
# File 'lib/teepee/commander.rb', line 692 def sinh number ensure_numeric Math.sinh number end |
#small(expressions) ⇒ Object
696 697 698 |
# File 'lib/teepee/commander.rb', line 696 def small expressions html_tag :small, expressions end |
#space ⇒ Object
708 709 710 |
# File 'lib/teepee/commander.rb', line 708 def space " " end |
#span_operator(expressions) ⇒ Object
712 713 714 |
# File 'lib/teepee/commander.rb', line 712 def span_operator expressions html_tag :span, expressions end |
#sqrt(number) ⇒ Object
704 705 706 |
# File 'lib/teepee/commander.rb', line 704 def sqrt number ensure_numeric Math.sqrt number end |
#squiggle ⇒ Object
700 701 702 |
# File 'lib/teepee/commander.rb', line 700 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
716 717 718 |
# File 'lib/teepee/commander.rb', line 716 def sub expressions html_tag :sub, expressions end |
#subtract_percentage(*numbers) ⇒ Object
189 190 191 |
# File 'lib/teepee/commander.rb', line 189 def subtract_percentage *numbers numbers.inject {|base, percent| base * (1-percent/100.0) } end |
#sup(expressions) ⇒ Object
720 721 722 |
# File 'lib/teepee/commander.rb', line 720 def sup expressions html_tag :sup, expressions end |
#table(expressions) ⇒ Object
724 725 726 |
# File 'lib/teepee/commander.rb', line 724 def table expressions html_tag :table, expressions end |
#table_data(expressions) ⇒ Object
728 729 730 |
# File 'lib/teepee/commander.rb', line 728 def table_data expressions html_tag :td, expressions end |
#table_header(expressions) ⇒ Object
732 733 734 |
# File 'lib/teepee/commander.rb', line 732 def table_header expressions html_tag :th, expressions end |
#table_row(expressions) ⇒ Object
736 737 738 |
# File 'lib/teepee/commander.rb', line 736 def table_row expressions html_tag :tr, expressions end |
#tag_id(id) ⇒ Object
740 741 742 |
# File 'lib/teepee/commander.rb', line 740 def tag_id id id_command_handler id, :Tag end |
#tan(angle) ⇒ Object
744 745 746 |
# File 'lib/teepee/commander.rb', line 744 def tan angle ensure_numeric Math.tan angle end |
#tanh(number) ⇒ Object
748 749 750 |
# File 'lib/teepee/commander.rb', line 748 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_constant ⇒ Object
752 753 754 |
# File 'lib/teepee/commander.rb', line 752 def true_constant "true" end |
#true_constant?(expression) ⇒ Boolean
139 140 141 |
# File 'lib/teepee/commander.rb', line 139 def true_constant? expression expression.to_s == "true" end |
#tt(expressions) ⇒ Object
756 757 758 |
# File 'lib/teepee/commander.rb', line 756 def tt expressions html_tag :tt, expressions end |
#u(expressions) ⇒ Object
760 761 762 |
# File 'lib/teepee/commander.rb', line 760 def u expressions html_tag :u, expressions end |
#unless_operator(expressions) ⇒ Object
764 765 766 767 768 769 770 771 772 773 774 775 |
# File 'lib/teepee/commander.rb', line 764 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 span_operator expressions end end end |
#user(user) ⇒ Object
777 778 779 780 781 782 783 |
# File 'lib/teepee/commander.rb', line 777 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
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
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
785 786 787 788 789 790 791 792 793 794 795 796 |
# File 'lib/teepee/commander.rb', line 785 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 span_operator expressions end end end |