Class: Teepee::Commander
- Inherits:
-
Object
- Object
- Teepee::Commander
- Defined in:
- lib/teepee/commander.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
- #%(numbers) ⇒ Object
- #*(numbers) ⇒ Object
- #**(numbers) ⇒ Object
-
#+(numbers) ⇒ Object
—————————————————————————-.
- #-(numbers) ⇒ Object
- #/(numbers) ⇒ Object
- #acos(angle) ⇒ Object
- #acosh(angle) ⇒ Object
- #add_percentage(numbers) ⇒ Object
- #asin(angle) ⇒ Object
- #asinh(angle) ⇒ Object
- #atan(angle) ⇒ Object
- #atanh(angle) ⇒ Object
- #b(expressions) ⇒ Object
- #backquote ⇒ Object
- #backslash ⇒ Object
- #big(expressions) ⇒ Object
- #bookmarks_folder_id(id) ⇒ Object
- #boolean_and(booleans) ⇒ Object
- #boolean_nand(booleans) ⇒ Object
- #boolean_nor(booleans) ⇒ Object
- #boolean_not(boolean) ⇒ Object
- #boolean_or(booleans) ⇒ Object
- #boolean_xnor(booleans) ⇒ Object
- #boolean_xor(booleans) ⇒ 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(angle) ⇒ Object
- #define(expressions) ⇒ Object
- #defined?(variables) ⇒ Boolean
- #degrees2radians(degrees) ⇒ Object
- #del(expressions) ⇒ Object
- #dollar ⇒ Object
- #dotimes(expressions) ⇒ 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
- #get_operator(variable) ⇒ 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
-
#initialize(params) ⇒ Commander
constructor
A new instance of Commander.
- #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(number) ⇒ 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(number) ⇒ 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
- #number_from_word(word) ⇒ Object
- #numeric?(*numbers) ⇒ Boolean
- #percent_total(numbers) ⇒ Object
- #pi ⇒ Object
- #pipe ⇒ Object
- #pipe?(expression) ⇒ Boolean
- #prog1_operator(expressions) ⇒ Object
- #progn_operator(expressions) ⇒ Object
- #prognil(expressions) ⇒ Object
- #radians2degrees(radians) ⇒ Object
- #right_brace ⇒ Object
- #right_bracket ⇒ Object
- #right_strip(expressions) ⇒ Object
- #round(number, precision = nil, *_) ⇒ Object
- #sin(angle) ⇒ Object
- #sinh(angle) ⇒ 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(angle) ⇒ Object
- #tb_href(target, string) ⇒ Object
- #to_numbers(words) ⇒ Object
- #true_constant ⇒ Object
- #true_constant?(expression) ⇒ Boolean
- #tt(expressions) ⇒ Object
- #u(expressions) ⇒ Object
- #undefine(expressions) ⇒ Object
- #unless_operator(expressions) ⇒ Object
- #user(user) ⇒ Object
- #valid_email_address?(email_address) ⇒ Boolean
- #valid_uri?(uri) ⇒ Boolean
- #when_operator(expressions) ⇒ Object
Constructor Details
#initialize(params) ⇒ Commander
Returns a new instance of Commander.
42 43 44 |
# File 'lib/teepee/commander.rb', line 42 def initialize params # We don't use the params in the base class, but might in derived classes. end |
Instance Attribute Details
#parser ⇒ Object
Returns the value of attribute parser.
40 41 42 |
# File 'lib/teepee/commander.rb', line 40 def parser @parser end |
Instance Method Details
#%(numbers) ⇒ Object
201 202 203 |
# File 'lib/teepee/commander.rb', line 201 def % numbers to_numbers(numbers).inject { |base, percent| base*percent/100.0 } end |
#*(numbers) ⇒ Object
184 185 186 |
# File 'lib/teepee/commander.rb', line 184 def * numbers ensure_numeric to_numbers(numbers).inject 1, :* end |
#**(numbers) ⇒ Object
197 198 199 |
# File 'lib/teepee/commander.rb', line 197 def ** numbers ensure_numeric to_numbers(numbers).reduce :** end |
#+(numbers) ⇒ Object
171 172 173 |
# File 'lib/teepee/commander.rb', line 171 def + numbers ensure_numeric to_numbers(numbers).inject 0, :+ end |
#-(numbers) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'lib/teepee/commander.rb', line 175 def - numbers numbers = to_numbers numbers if numbers.length == 1 ensure_numeric -numbers.first else ensure_numeric numbers.reduce :- end end |
#/(numbers) ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/teepee/commander.rb', line 188 def / numbers numbers = to_numbers numbers if numbers.length == 1 ensure_numeric 1 / numbers.first else ensure_numeric numbers.reduce :/ end end |
#acos(angle) ⇒ Object
217 218 219 |
# File 'lib/teepee/commander.rb', line 217 def acos angle ensure_numeric Math.acos angle.to_number end |
#acosh(angle) ⇒ Object
221 222 223 |
# File 'lib/teepee/commander.rb', line 221 def acosh angle ensure_numeric Math.acosh angle.to_number end |
#add_percentage(numbers) ⇒ Object
205 206 207 |
# File 'lib/teepee/commander.rb', line 205 def add_percentage numbers to_numbers(numbers).inject {|base, percent| base * (1+percent/100.0) } end |
#asin(angle) ⇒ Object
225 226 227 |
# File 'lib/teepee/commander.rb', line 225 def asin angle ensure_numeric Math.asin angle.to_number end |
#asinh(angle) ⇒ Object
229 230 231 |
# File 'lib/teepee/commander.rb', line 229 def asinh angle ensure_numeric Math.asinh angle.to_number end |
#atan(angle) ⇒ Object
233 234 235 |
# File 'lib/teepee/commander.rb', line 233 def atan angle ensure_numeric Math.atan angle.to_number end |
#atanh(angle) ⇒ Object
237 238 239 |
# File 'lib/teepee/commander.rb', line 237 def atanh angle ensure_numeric Math.atanh angle.to_number end |
#b(expressions) ⇒ Object
241 242 243 |
# File 'lib/teepee/commander.rb', line 241 def b expressions html_tag :b, expressions end |
#backquote ⇒ Object
245 246 247 |
# File 'lib/teepee/commander.rb', line 245 def backquote "`" end |
#backslash ⇒ Object
249 250 251 |
# File 'lib/teepee/commander.rb', line 249 def backslash "\\" end |
#big(expressions) ⇒ Object
253 254 255 |
# File 'lib/teepee/commander.rb', line 253 def big expressions html_tag :big, expressions end |
#bookmarks_folder_id(id) ⇒ Object
257 258 259 |
# File 'lib/teepee/commander.rb', line 257 def bookmarks_folder_id id id_command_handler id, :Folder, "folder", "folders", "folders/bookmarks_inline", "bookmarks" end |
#boolean_and(booleans) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/teepee/commander.rb', line 261 def boolean_and booleans if booleans.empty? true_constant elsif false_constant? booleans.first false_constant elsif true_constant? booleans.first or booleans.first.kind_of? WhitespaceToken boolean_and booleans[1..-1] else command_error "Not a boolean value #{booleans.first}" end end |
#boolean_nand(booleans) ⇒ Object
273 274 275 |
# File 'lib/teepee/commander.rb', line 273 def boolean_nand booleans boolean_not boolean_and booleans end |
#boolean_nor(booleans) ⇒ Object
277 278 279 |
# File 'lib/teepee/commander.rb', line 277 def boolean_nor booleans boolean_not boolean_or booleans end |
#boolean_not(boolean) ⇒ Object
281 282 283 284 285 286 287 288 289 |
# File 'lib/teepee/commander.rb', line 281 def boolean_not boolean if true_constant? boolean false_constant elsif false_constant? boolean true_constant else command_error "Not a boolean value" end end |
#boolean_or(booleans) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/teepee/commander.rb', line 291 def boolean_or booleans if booleans.empty? false_constant elsif true_constant? booleans.first true_constant elsif false_constant? booleans.first or booleans.first.kind_of? WhitespaceToken boolean_or booleans[1..-1] else command_error "Not a boolean value" end end |
#boolean_xnor(booleans) ⇒ Object
303 304 305 |
# File 'lib/teepee/commander.rb', line 303 def boolean_xnor booleans boolean_not boolean_xor booleans end |
#boolean_xor(booleans) ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/teepee/commander.rb', line 307 def boolean_xor booleans # 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 booleans.empty? false_constant else any_trues = false booleans.each do |boolean| if true_constant? boolean if any_trues return false_constant else any_trues = true end elsif false_constant? boolean # do nothing elsif boolean.kind_of? WhitespaceToken # do nothing else return command_error "Not a boolean value" end end return any_trues.to_s end end |
#br ⇒ Object
336 337 338 |
# File 'lib/teepee/commander.rb', line 336 def br html_tag :br, nil end |
#case_operator(expressions) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/teepee/commander.rb', line 340 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
355 356 357 |
# File 'lib/teepee/commander.rb', line 355 def ceiling number ensure_numeric number.to_number.ceil end |
#command_error(message) ⇒ Object
52 53 54 |
# File 'lib/teepee/commander.rb', line 52 def command_error %{<span style="color: red">[#{message}]</span>} end |
#command_not_yet_implemented(command) ⇒ Object
56 57 58 |
# File 'lib/teepee/commander.rb', line 56 def command_not_yet_implemented command command_error "The command #{command} is not yet implemented." end |
#comment(expressions) ⇒ Object
359 360 361 |
# File 'lib/teepee/commander.rb', line 359 def comment expressions nil end |
#cond_operator(expressions) ⇒ Object
363 364 365 366 367 368 369 370 |
# File 'lib/teepee/commander.rb', line 363 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
372 373 374 |
# File 'lib/teepee/commander.rb', line 372 def cos angle ensure_numeric Math.cos angle.to_number end |
#cosh(angle) ⇒ Object
376 377 378 |
# File 'lib/teepee/commander.rb', line 376 def cosh angle ensure_numeric Math.cosh angle.to_number end |
#define(expressions) ⇒ Object
380 381 382 383 384 385 386 |
# File 'lib/teepee/commander.rb', line 380 def define expressions variable, _, value = expressions k = variable.to_html v = value.to_html @parser.variables[k] = v get_operator k end |
#defined?(variables) ⇒ Boolean
388 389 390 391 392 393 394 |
# File 'lib/teepee/commander.rb', line 388 def defined? variables if Set.new(variables.map(&:to_html)).subset? Set.new(@parser.variables.keys) true_constant else false_constant end end |
#degrees2radians(degrees) ⇒ Object
396 397 398 |
# File 'lib/teepee/commander.rb', line 396 def degrees2radians degrees ensure_numeric degrees.to_number * Math::PI / 180.0 end |
#del(expressions) ⇒ Object
400 401 402 |
# File 'lib/teepee/commander.rb', line 400 def del expressions html_tag :del, expressions end |
#dollar ⇒ Object
404 405 406 |
# File 'lib/teepee/commander.rb', line 404 def dollar "$" end |
#dotimes(expressions) ⇒ Object
408 409 410 411 412 |
# File 'lib/teepee/commander.rb', line 408 def dotimes expressions n = expressions.first.to_number return "" if n.nil? or n < 1 span_operator expressions[1..-1] * n end |
#e ⇒ Object
414 415 416 |
# File 'lib/teepee/commander.rb', line 414 def e Math::E end |
#ensure_boolean(boolean) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/teepee/commander.rb', line 74 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
64 65 66 67 68 69 70 71 72 |
# File 'lib/teepee/commander.rb', line 64 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
428 429 430 |
# File 'lib/teepee/commander.rb', line 428 def enumerate expressions html_tag :ol, expressions end |
#enumerate_lowercase(expressions) ⇒ Object
440 441 442 |
# File 'lib/teepee/commander.rb', line 440 def enumerate_lowercase expressions html_tag :ol, expressions, {type: "a"} end |
#enumerate_numeric(expressions) ⇒ Object
432 433 434 |
# File 'lib/teepee/commander.rb', line 432 def enumerate_numeric expressions html_tag :ol, expressions, {type: "1"} end |
#enumerate_roman_lowercase(expressions) ⇒ Object
448 449 450 |
# File 'lib/teepee/commander.rb', line 448 def enumerate_roman_lowercase expressions html_tag :ol, expressions, {type: "i"} end |
#enumerate_roman_uppercase(expressions) ⇒ Object
444 445 446 |
# File 'lib/teepee/commander.rb', line 444 def enumerate_roman_uppercase expressions html_tag :ol, expressions, {type: "I"} end |
#enumerate_uppercase(expressions) ⇒ Object
436 437 438 |
# File 'lib/teepee/commander.rb', line 436 def enumerate_uppercase expressions html_tag :ol, expressions, {type: "A"} end |
#equal(expressions) ⇒ Object
418 419 420 421 422 423 424 425 426 |
# File 'lib/teepee/commander.rb', line 418 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
452 453 454 |
# File 'lib/teepee/commander.rb', line 452 def erf number ensure_numeric Math.erf number.to_number end |
#erfc(number) ⇒ Object
456 457 458 |
# File 'lib/teepee/commander.rb', line 456 def erfc number ensure_numeric Math.erfc number.to_number end |
#false_constant ⇒ Object
460 461 462 |
# File 'lib/teepee/commander.rb', line 460 def false_constant "false" end |
#false_constant?(expression) ⇒ Boolean
149 150 151 |
# File 'lib/teepee/commander.rb', line 149 def false_constant? expression expression.to_s == "false" end |
#floor(number) ⇒ Object
464 465 466 |
# File 'lib/teepee/commander.rb', line 464 def floor number ensure_numeric number.to_number.floor end |
#folder_id(id) ⇒ Object
468 469 470 |
# File 'lib/teepee/commander.rb', line 468 def folder_id id id_command_handler id, :Folder end |
#forum_id(id) ⇒ Object
472 473 474 |
# File 'lib/teepee/commander.rb', line 472 def forum_id id id_command_handler id, :Forum end |
#gamma(number) ⇒ Object
476 477 478 |
# File 'lib/teepee/commander.rb', line 476 def gamma number ensure_numeric Math.gamma number.to_number end |
#get_operator(variable) ⇒ Object
480 481 482 |
# File 'lib/teepee/commander.rb', line 480 def get_operator variable @parser.variables[variable.to_html].to_html end |
#greater_than(numbers) ⇒ Object
484 485 486 487 488 489 490 491 492 |
# File 'lib/teepee/commander.rb', line 484 def greater_than numbers if numbers.empty? true_constant elsif numbers.length == 1 true_constant else numbers[0].to_number > numbers[1].to_number and greater_than numbers.rest end end |
#greater_than_or_equal(numbers) ⇒ Object
494 495 496 497 498 499 500 501 502 |
# File 'lib/teepee/commander.rb', line 494 def greater_than_or_equal numbers if numbers.empty? true_constant elsif numbers.length == 1 true_constant else numbers[0].to_number >= numbers[1].to_number and greater_than_or_equal numbers.rest end end |
#h1(expressions) ⇒ Object
504 505 506 |
# File 'lib/teepee/commander.rb', line 504 def h1 expressions html_tag :h1, expressions end |
#h2(expressions) ⇒ Object
508 509 510 |
# File 'lib/teepee/commander.rb', line 508 def h2 expressions html_tag :h2, expressions end |
#h3(expressions) ⇒ Object
512 513 514 |
# File 'lib/teepee/commander.rb', line 512 def h3 expressions html_tag :h3, expressions end |
#h4(expressions) ⇒ Object
516 517 518 |
# File 'lib/teepee/commander.rb', line 516 def h4 expressions html_tag :h4, expressions end |
#h5(expressions) ⇒ Object
520 521 522 |
# File 'lib/teepee/commander.rb', line 520 def h5 expressions html_tag :h5, expressions end |
#h6(expressions) ⇒ Object
524 525 526 |
# File 'lib/teepee/commander.rb', line 524 def h6 expressions html_tag :h6, expressions end |
#html_tag(tag, expressions, attribs = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/teepee/commander.rb', line 82 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
585 586 587 |
# File 'lib/teepee/commander.rb', line 585 def hypot numbers ensure_numeric Math.sqrt to_numbers(numbers).map {|n| n**2} end |
#i ⇒ Object
528 529 530 |
# File 'lib/teepee/commander.rb', line 528 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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/teepee/commander.rb', line 108 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
532 533 534 535 536 537 538 539 540 |
# File 'lib/teepee/commander.rb', line 532 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
542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/teepee/commander.rb', line 542 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
557 558 559 |
# File 'lib/teepee/commander.rb', line 557 def it expressions html_tag :i, expressions end |
#item(expressions) ⇒ Object
561 562 563 |
# File 'lib/teepee/commander.rb', line 561 def item expressions html_tag :li, expressions end |
#itemize(expressions) ⇒ Object
565 566 567 |
# File 'lib/teepee/commander.rb', line 565 def itemize expressions html_tag :ul, expressions end |
#itemize_circle(expressions) ⇒ Object
573 574 575 |
# File 'lib/teepee/commander.rb', line 573 def itemize_circle expressions html_tag :ul, expressions, {style: "list-style-type:circle"} end |
#itemize_disc(expressions) ⇒ Object
569 570 571 |
# File 'lib/teepee/commander.rb', line 569 def itemize_disc expressions html_tag :ul, expressions, {style: "list-style-type:disc"} end |
#itemize_none(expressions) ⇒ Object
581 582 583 |
# File 'lib/teepee/commander.rb', line 581 def itemize_none expressions html_tag :ul, expressions, {style: "list-style-type:none"} end |
#itemize_square(expressions) ⇒ Object
577 578 579 |
# File 'lib/teepee/commander.rb', line 577 def itemize_square expressions html_tag :ul, expressions, {style: "list-style-type:square"} end |
#keyword_id(id) ⇒ Object
589 590 591 |
# File 'lib/teepee/commander.rb', line 589 def keyword_id id id_command_handler id, :Keyword end |
#ld(number) ⇒ Object
593 594 595 |
# File 'lib/teepee/commander.rb', line 593 def ld number ensure_numeric Math.log2 number.to_number end |
#ldexp(fraction, exponent) ⇒ Object
597 598 599 |
# File 'lib/teepee/commander.rb', line 597 def ldexp fraction, exponent ensure_numeric Math.ldexp fraction.to_number, exponent.to_number end |
#left_brace ⇒ Object
601 602 603 |
# File 'lib/teepee/commander.rb', line 601 def left_brace "{" end |
#left_bracket ⇒ Object
605 606 607 |
# File 'lib/teepee/commander.rb', line 605 def left_bracket "[" end |
#left_strip(expressions) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/teepee/commander.rb', line 123 def left_strip expressions while expressions.first.kind_of? WhitespaceToken expressions.shift end expressions end |
#less_than(numbers) ⇒ Object
609 610 611 612 613 614 615 616 617 |
# File 'lib/teepee/commander.rb', line 609 def less_than numbers if numbers.empty? true_constant elsif numbers.length == 1 true_constant else numbers[0].to_number < numbers[1].to_number and less_than numbers.rest end end |
#less_than_or_equal(numbers) ⇒ Object
619 620 621 622 623 624 625 626 627 |
# File 'lib/teepee/commander.rb', line 619 def less_than_or_equal numbers if numbers.empty? true_constant elsif numbers.length == 1 true_constant else numbers[0].to_number <= numbers[1].to_number and less_than_or_equal numbers.rest end end |
#lgamma(number) ⇒ Object
629 630 631 |
# File 'lib/teepee/commander.rb', line 629 def lgamma number ensure_numeric Math::lgamma(number.to_number).first end |
#link(expressions) ⇒ Object
633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/teepee/commander.rb', line 633 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
645 646 647 |
# File 'lib/teepee/commander.rb', line 645 def link_id id id_command_handler id, :Link end |
#ln(number) ⇒ Object
649 650 651 |
# File 'lib/teepee/commander.rb', line 649 def ln number ensure_numeric Math.log number.to_number end |
#log(base, number) ⇒ Object
653 654 655 656 657 658 659 660 |
# File 'lib/teepee/commander.rb', line 653 def log base, number if number.nil? number, base = base, number ensure_numeric Math.log10 number.to_number # default to log base 10 else ensure_numeric Math.log number.to_number, base.to_number end end |
#log10(number) ⇒ Object
662 663 664 |
# File 'lib/teepee/commander.rb', line 662 def log10 number ensure_numeric Math.log10 number.to_number end |
#mailto(email_address) ⇒ Object
666 667 668 669 670 671 672 673 |
# File 'lib/teepee/commander.rb', line 666 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
675 676 677 |
# File 'lib/teepee/commander.rb', line 675 def mod numbers ensure_numeric to_numbers(numbers).reduce :% end |
#nbsp(count) ⇒ Object
679 680 681 682 683 684 685 |
# File 'lib/teepee/commander.rb', line 679 def nbsp count if count and count.to_number and count.to_number > 0 " " * count.to_number else " " end end |
#not_equal(numbers) ⇒ Object
687 688 689 690 691 692 693 694 695 |
# File 'lib/teepee/commander.rb', line 687 def not_equal numbers if numbers.empty? true_constant elsif numbers.length == 1 true_constant else numbers[0].to_number != numbers[1].to_number and equal numbers.rest end end |
#note_id(id) ⇒ Object
697 698 699 |
# File 'lib/teepee/commander.rb', line 697 def note_id id id_command_handler id, :Note end |
#number_from_word(word) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/teepee/commander.rb', line 157 def number_from_word word begin word.to_number rescue ArgumentError, NoMethodError nil end end |
#numeric?(*numbers) ⇒ Boolean
60 61 62 |
# File 'lib/teepee/commander.rb', line 60 def numeric? *numbers numbers.all? {|number| number.kind_of? Numeric} end |
#percent_total(numbers) ⇒ Object
213 214 215 |
# File 'lib/teepee/commander.rb', line 213 def percent_total numbers to_numbers(numbers).inject {|total, part| Float(part)/Float(total)*100.0 } end |
#pi ⇒ Object
701 702 703 |
# File 'lib/teepee/commander.rb', line 701 def pi Math::PI end |
#pipe ⇒ Object
705 706 707 |
# File 'lib/teepee/commander.rb', line 705 def pipe "|" end |
#pipe?(expression) ⇒ Boolean
153 154 155 |
# File 'lib/teepee/commander.rb', line 153 def pipe? expression expression.is_a? PipeToken end |
#prog1_operator(expressions) ⇒ Object
709 710 711 |
# File 'lib/teepee/commander.rb', line 709 def prog1_operator expressions expressions.map(&:to_html).first end |
#progn_operator(expressions) ⇒ Object
713 714 715 |
# File 'lib/teepee/commander.rb', line 713 def progn_operator expressions expressions.map(&:to_html).last end |
#prognil(expressions) ⇒ Object
717 718 719 720 |
# File 'lib/teepee/commander.rb', line 717 def prognil expressions expressions.map(&:to_html) "" end |
#radians2degrees(radians) ⇒ Object
722 723 724 |
# File 'lib/teepee/commander.rb', line 722 def radians2degrees radians ensure_numeric(radians.to_number * 180.0 / Math::PI) end |
#right_brace ⇒ Object
726 727 728 |
# File 'lib/teepee/commander.rb', line 726 def right_brace "}" end |
#right_bracket ⇒ Object
730 731 732 |
# File 'lib/teepee/commander.rb', line 730 def right_bracket "]" end |
#right_strip(expressions) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/teepee/commander.rb', line 130 def right_strip expressions while expressions.last.kind_of? WhitespaceToken expressions.pop end expressions end |
#round(number, precision = nil, *_) ⇒ Object
734 735 736 737 738 739 740 |
# File 'lib/teepee/commander.rb', line 734 def round number, precision = nil, *_ if precision.nil? or precision.to_number.nil? ensure_numeric number.to_number.round else ensure_numeric number.to_number.round precision.to_number end end |
#sin(angle) ⇒ Object
742 743 744 |
# File 'lib/teepee/commander.rb', line 742 def sin angle ensure_numeric Math.sin angle.to_number end |
#sinh(angle) ⇒ Object
746 747 748 |
# File 'lib/teepee/commander.rb', line 746 def sinh angle ensure_numeric Math.sinh angle.to_number end |
#small(expressions) ⇒ Object
750 751 752 |
# File 'lib/teepee/commander.rb', line 750 def small expressions html_tag :small, expressions end |
#space ⇒ Object
762 763 764 |
# File 'lib/teepee/commander.rb', line 762 def space " " end |
#span_operator(expressions) ⇒ Object
766 767 768 |
# File 'lib/teepee/commander.rb', line 766 def span_operator expressions html_tag :span, expressions end |
#sqrt(number) ⇒ Object
758 759 760 |
# File 'lib/teepee/commander.rb', line 758 def sqrt number ensure_numeric Math.sqrt number.to_number end |
#squiggle ⇒ Object
754 755 756 |
# File 'lib/teepee/commander.rb', line 754 def squiggle "~" end |
#strip(expressions) ⇒ Object
137 138 139 |
# File 'lib/teepee/commander.rb', line 137 def strip expressions left_strip right_strip expressions end |
#sub(expressions) ⇒ Object
770 771 772 |
# File 'lib/teepee/commander.rb', line 770 def sub expressions html_tag :sub, expressions end |
#subtract_percentage(numbers) ⇒ Object
209 210 211 |
# File 'lib/teepee/commander.rb', line 209 def subtract_percentage numbers to_numbers(numbers).inject {|base, percent| base * (1-percent/100.0) } end |
#sup(expressions) ⇒ Object
774 775 776 |
# File 'lib/teepee/commander.rb', line 774 def sup expressions html_tag :sup, expressions end |
#table(expressions) ⇒ Object
778 779 780 |
# File 'lib/teepee/commander.rb', line 778 def table expressions html_tag :table, expressions end |
#table_data(expressions) ⇒ Object
782 783 784 |
# File 'lib/teepee/commander.rb', line 782 def table_data expressions html_tag :td, expressions end |
#table_header(expressions) ⇒ Object
786 787 788 |
# File 'lib/teepee/commander.rb', line 786 def table_header expressions html_tag :th, expressions end |
#table_row(expressions) ⇒ Object
790 791 792 |
# File 'lib/teepee/commander.rb', line 790 def table_row expressions html_tag :tr, expressions end |
#tag_id(id) ⇒ Object
794 795 796 |
# File 'lib/teepee/commander.rb', line 794 def tag_id id id_command_handler id, :Tag end |
#tan(angle) ⇒ Object
798 799 800 |
# File 'lib/teepee/commander.rb', line 798 def tan angle ensure_numeric Math.tan angle.to_number end |
#tanh(angle) ⇒ Object
802 803 804 |
# File 'lib/teepee/commander.rb', line 802 def tanh angle ensure_numeric Math.tanh angle.to_number end |
#tb_href(target, string) ⇒ Object
104 105 106 |
# File 'lib/teepee/commander.rb', line 104 def tb_href target, string %{<a href="#{TB_COM}/#{target}">#{string}</a>} end |
#to_numbers(words) ⇒ Object
165 166 167 |
# File 'lib/teepee/commander.rb', line 165 def to_numbers words words.map {|word| number_from_word word}.reject &:nil? end |
#true_constant ⇒ Object
806 807 808 |
# File 'lib/teepee/commander.rb', line 806 def true_constant "true" end |
#true_constant?(expression) ⇒ Boolean
145 146 147 |
# File 'lib/teepee/commander.rb', line 145 def true_constant? expression expression.to_s == "true" end |
#tt(expressions) ⇒ Object
810 811 812 |
# File 'lib/teepee/commander.rb', line 810 def tt expressions html_tag :tt, expressions end |
#u(expressions) ⇒ Object
814 815 816 |
# File 'lib/teepee/commander.rb', line 814 def u expressions html_tag :u, expressions end |
#undefine(expressions) ⇒ Object
818 819 820 821 822 823 |
# File 'lib/teepee/commander.rb', line 818 def undefine expressions expressions.each do |expression| @parser.variables.delete expression.to_html end "" end |
#unless_operator(expressions) ⇒ Object
825 826 827 828 829 830 831 832 833 834 835 836 |
# File 'lib/teepee/commander.rb', line 825 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
838 839 840 841 842 843 844 |
# File 'lib/teepee/commander.rb', line 838 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
141 142 143 |
# File 'lib/teepee/commander.rb', line 141 def valid_email_address? email_address email_address =~ /\A[[:graph:]]+@[\w.]+\z/ end |
#valid_uri?(uri) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/teepee/commander.rb', line 46 def valid_uri? uri (!! (u = URI.parse(uri))) and not u.scheme.nil? rescue URI::InvalidURIError false end |
#when_operator(expressions) ⇒ Object
846 847 848 849 850 851 852 853 854 855 856 857 |
# File 'lib/teepee/commander.rb', line 846 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 |