Class: Livetext::Functions

Inherits:
Object show all
Defined in:
lib/livetext/functions.rb

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

Instance Method Summary collapse

Class Attribute Details

.paramObject

kill this?



11
12
13
# File 'lib/livetext/functions.rb', line 11

def param
  @param
end

Instance Method Details

#b(param = nil) ⇒ Object



88
# File 'lib/livetext/functions.rb', line 88

def b(param=nil);    simple_format(param, :b); end

#bi(param = nil) ⇒ Object



92
# File 'lib/livetext/functions.rb', line 92

def bi(param=nil);   simple_format(param, :b, :i); end

#bis(param = nil) ⇒ Object



99
# File 'lib/livetext/functions.rb', line 99

def bis(param=nil);  simple_format(param, :b, :i, :s); end

#bit(param = nil) ⇒ Object



98
# File 'lib/livetext/functions.rb', line 98

def bit(param=nil);  simple_format(param, :b, :i, :t); end

#bits(param = nil) ⇒ Object



102
# File 'lib/livetext/functions.rb', line 102

def bits(param=nil); simple_format(param, :b, :i, :t, :s); end

#br(n = "1") ⇒ Object



68
69
70
71
# File 'lib/livetext/functions.rb', line 68

def br(n="1")
  n = n.to_i
  "<br>"*n
end

#bs(param = nil) ⇒ Object



94
# File 'lib/livetext/functions.rb', line 94

def bs(param=nil);   simple_format(param, :b, :s); end

#bt(param = nil) ⇒ Object



93
# File 'lib/livetext/functions.rb', line 93

def bt(param=nil);   simple_format(param, :b, :t); end

#bts(param = nil) ⇒ Object



100
# File 'lib/livetext/functions.rb', line 100

def bts(param=nil);  simple_format(param, :b, :t, :s); end

#code_lines(param = nil) ⇒ Object



14
15
16
# File 'lib/livetext/functions.rb', line 14

def code_lines(param = nil)
  $code_lines.to_i  # FIXME pleeease
end

#date(param = nil) ⇒ Object



46
47
48
# File 'lib/livetext/functions.rb', line 46

def date(param=nil)
  Time.now.strftime("%F")
end

#i(param = nil) ⇒ Object



89
# File 'lib/livetext/functions.rb', line 89

def i(param=nil);    simple_format(param, :i); end

#is(param = nil) ⇒ Object



96
# File 'lib/livetext/functions.rb', line 96

def is(param=nil);   simple_format(param, :i, :s); end

#isqrt(param = nil) ⇒ Object

FIXME Function parameters need to be fixed…



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/livetext/functions.rb', line 24

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



95
# File 'lib/livetext/functions.rb', line 95

def it(param=nil);   simple_format(param, :i, :t); end

#its(param = nil) ⇒ Object



101
# File 'lib/livetext/functions.rb', line 101

def its(param=nil);  simple_format(param, :i, :t, :s); end


63
64
65
66
# File 'lib/livetext/functions.rb', line 63

def link(param=nil)
  text, url = param.split("|", 2)  # reverse these?
  "<a style='text-decoration: none' href='#{url}'>#{text}</a>"
end

#ns(param = nil) ⇒ Object



18
19
20
# File 'lib/livetext/functions.rb', line 18

def ns(param = nil)
  "\b"
end

#pwd(param = nil) ⇒ Object



54
55
56
# File 'lib/livetext/functions.rb', line 54

def pwd(param=nil)
  ::Dir.pwd
end

#rand(param = nil) ⇒ Object



58
59
60
61
# File 'lib/livetext/functions.rb', line 58

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



37
38
39
40
41
42
43
44
# File 'lib/livetext/functions.rb', line 37

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



91
# File 'lib/livetext/functions.rb', line 91

def s(param=nil);    simple_format(param, :s); end

#simple_format(param = nil, *args) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/livetext/functions.rb', line 78

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



90
# File 'lib/livetext/functions.rb', line 90

def t(param=nil);    simple_format(param, :t); end

#time(param = nil) ⇒ Object



50
51
52
# File 'lib/livetext/functions.rb', line 50

def time(param=nil)
  Time.now.strftime("%T")
end

#ts(param = nil) ⇒ Object



97
# File 'lib/livetext/functions.rb', line 97

def ts(param=nil);   simple_format(param, :t, :s); end

#yt(param) ⇒ Object

FIXME uh, this is crap



73
74
75
76
# File 'lib/livetext/functions.rb', line 73

def yt(param)   # FIXME uh, this is crap
  param = self.class.param
  "https://www.youtube.com/watch?v=#{param}"
end