Class: Livetext::Functions
Overview
Class Functions is where ‘$$func’ functions are stored dynamically… user-def AND pre-def??
Constant Summary collapse
- Formats =
::Livetext::Standard::SimpleFormats
Class Attribute Summary collapse
-
.param ⇒ Object
kill this?.
Instance Method Summary collapse
- #b(param = nil) ⇒ Object
- #bi(param = nil) ⇒ Object
- #bis(param = nil) ⇒ Object
- #bit(param = nil) ⇒ Object
- #bits(param = nil) ⇒ Object
- #br(n = "1") ⇒ Object
- #bs(param = nil) ⇒ Object
- #bt(param = nil) ⇒ Object
- #bts(param = nil) ⇒ Object
- #date(param = nil) ⇒ Object
- #i(param = nil) ⇒ Object
- #is(param = nil) ⇒ Object
-
#isqrt(param = nil) ⇒ Object
FIXME Function parameters need to be fixed…
- #it(param = nil) ⇒ Object
- #its(param = nil) ⇒ Object
- #link(param = nil) ⇒ Object
- #pwd(param = nil) ⇒ Object
- #rand(param = nil) ⇒ Object
-
#reverse(param = nil) ⇒ Object
again, just for testing.
- #s(param = nil) ⇒ Object
- #simple_format(param = nil, *args) ⇒ Object
- #t(param = nil) ⇒ Object
- #time(param = nil) ⇒ Object
- #ts(param = nil) ⇒ Object
-
#yt(param) ⇒ Object
FIXME uh, this is crap.
Class Attribute Details
.param ⇒ Object
kill this?
11 12 13 |
# File 'lib/livetext/functions.rb', line 11 def param @param end |
Instance Method Details
#b(param = nil) ⇒ Object
80 |
# File 'lib/livetext/functions.rb', line 80 def b(param=nil); simple_format(param, :b); end |
#bi(param = nil) ⇒ Object
84 |
# File 'lib/livetext/functions.rb', line 84 def bi(param=nil); simple_format(param, :b, :i); end |
#bis(param = nil) ⇒ Object
91 |
# File 'lib/livetext/functions.rb', line 91 def bis(param=nil); simple_format(param, :b, :i, :s); end |
#bit(param = nil) ⇒ Object
90 |
# File 'lib/livetext/functions.rb', line 90 def bit(param=nil); simple_format(param, :b, :i, :t); end |
#bits(param = nil) ⇒ Object
94 |
# File 'lib/livetext/functions.rb', line 94 def bits(param=nil); simple_format(param, :b, :i, :t, :s); end |
#br(n = "1") ⇒ Object
60 61 62 63 |
# File 'lib/livetext/functions.rb', line 60 def br(n="1") n = n.to_i "<br>"*n end |
#bs(param = nil) ⇒ Object
86 |
# File 'lib/livetext/functions.rb', line 86 def bs(param=nil); simple_format(param, :b, :s); end |
#bt(param = nil) ⇒ Object
85 |
# File 'lib/livetext/functions.rb', line 85 def bt(param=nil); simple_format(param, :b, :t); end |
#bts(param = nil) ⇒ Object
92 |
# File 'lib/livetext/functions.rb', line 92 def bts(param=nil); simple_format(param, :b, :t, :s); end |
#date(param = nil) ⇒ Object
38 39 40 |
# File 'lib/livetext/functions.rb', line 38 def date(param=nil) Time.now.strftime("%F") end |
#i(param = nil) ⇒ Object
81 |
# File 'lib/livetext/functions.rb', line 81 def i(param=nil); simple_format(param, :i); end |
#is(param = nil) ⇒ Object
88 |
# File 'lib/livetext/functions.rb', line 88 def is(param=nil); simple_format(param, :i, :s); end |
#isqrt(param = nil) ⇒ Object
FIXME Function parameters need to be fixed…
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/livetext/functions.rb', line 16 def isqrt(param = nil) # "integer square root" - Just for testing arg = num = param # Takes any number if num.nil? || num.empty? arg = "NO PARAM" # Just for error text end # Integer()/Float() can raise error num = num.include?(".") ? Float(num) : Integer(num) # Returns truncated integer Math.sqrt(num).to_i # user need not do to_s rescue => err # Malformed number? negative? "[Error evaluating $$isqrt(#{arg})]" end |
#it(param = nil) ⇒ Object
87 |
# File 'lib/livetext/functions.rb', line 87 def it(param=nil); simple_format(param, :i, :t); end |
#its(param = nil) ⇒ Object
93 |
# File 'lib/livetext/functions.rb', line 93 def its(param=nil); simple_format(param, :i, :t, :s); end |
#link(param = nil) ⇒ Object
55 56 57 58 |
# File 'lib/livetext/functions.rb', line 55 def link(param=nil) text, url = param.split("|", 2) # reverse these? "<a style='text-decoration: none' href='#{url}'>#{text}</a>" end |
#pwd(param = nil) ⇒ Object
46 47 48 |
# File 'lib/livetext/functions.rb', line 46 def pwd(param=nil) ::Dir.pwd end |
#rand(param = nil) ⇒ Object
50 51 52 53 |
# File 'lib/livetext/functions.rb', line 50 def rand(param=nil) n1, n2 = param.split.map(&:to_i) ::Kernel.rand(n1..n2).to_s end |
#reverse(param = nil) ⇒ Object
again, just for testing
29 30 31 32 33 34 35 36 |
# File 'lib/livetext/functions.rb', line 29 def reverse(param=nil) # again, just for testing arg = param if arg.nil? || arg.empty? return "(reverse: No parameter)" else return arg.reverse end end |
#s(param = nil) ⇒ Object
83 |
# File 'lib/livetext/functions.rb', line 83 def s(param=nil); simple_format(param, :s); end |
#simple_format(param = nil, *args) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/livetext/functions.rb', line 70 def simple_format(param=nil, *args) param ||= "NO PARAMETER" pairs = Formats.values_at(*args) str = param.dup pairs.reverse.each do |pair| str = "#{pair.first}#{str}#{pair.last}" end str end |
#t(param = nil) ⇒ Object
82 |
# File 'lib/livetext/functions.rb', line 82 def t(param=nil); simple_format(param, :t); end |
#time(param = nil) ⇒ Object
42 43 44 |
# File 'lib/livetext/functions.rb', line 42 def time(param=nil) Time.now.strftime("%T") end |
#ts(param = nil) ⇒ Object
89 |
# File 'lib/livetext/functions.rb', line 89 def ts(param=nil); simple_format(param, :t, :s); end |
#yt(param) ⇒ Object
FIXME uh, this is crap
65 66 67 68 |
# File 'lib/livetext/functions.rb', line 65 def yt(param) # FIXME uh, this is crap param = self.class.param "https://www.youtube.com/watch?v=#{param}" end |