Class: RBText::Ftext

Inherits:
Object
  • Object
show all
Defined in:
lib/rbtext/ftext.rb

Direct Known Subclasses

Ft

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Ftext

Returns a new instance of Ftext.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rbtext/ftext.rb', line 3

def initialize(str)
  @original_text = str
  @text = ""
  
  str = str.gsub("_.", "\0001").gsub("._", "\0002").gsub("_", "\0000").gsub("\0001", "_.").gsub("\0002", "._").split("_").map{|x|x.gsub("\0000", "_")}

  for x in str do
    if x[0] == "." && x[x.length-1] == "." && x.split(":").length == 2
      x = x.downcase.gsub(".", "").gsub("-","_")
      x = x.split(":")

      if x[0] == "cf" || x[0] == "c"
        @text << RBText::Colors.color(x[1].to_sym)
      elsif x[0] == "cb"
        @text << RBText::Colors.color(x[1].to_sym, type: :bg)
      elsif x[0] == "cfn" || x[0] == "cn"
        @text << RBText::Colors.num_color(x[1])
      elsif x[0] == "cbn"
        @text << RBText::Colors.num_color(x[1], type: :bg)
      elsif x[0] == "f"
        if x[1] == "reset"
          @text << RBText::Formatting.reset
        elsif x[1] == "bold"
          @text << RBText::Formatting.bold
        elsif x[1] == "faint"
          @text << RBText::Formatting.faint
        elsif x[1] == "italic"
          @text << RBText::Formatting.italic
        elsif x[1] == "underline"
          @text << RBText::Formatting.underline
        elsif x[1] == "strikethrough"
          @text << RBText::Formatting.strikethrough
        elsif x[1] == "blinking"
          @text << RBText::Formatting.blinking
        end
      elsif x[0] == "rf"
        if x[1] == "bold"
          @text << RBText::Formatting.reset(R::F.bold)
        elsif x[1] == "faint"
          @text << RBText::Formatting.reset(R::F.faint)
        elsif x[1] == "italic"
          @text << RBText::Formatting.reset(R::F.italic)
        elsif x[1] == "underline"
          @text << RBText::Formatting.reset(R::F.underline)
        elsif x[1] == "strikethrough"
          @text << RBText::Formatting.reset(R::F.strikethrough)
        elsif x[1] == "blinking"
          @text << RBText::Formatting.reset(R::F.blinking)
        end
      end
    else
      @text << x
    end 
  end

  @text << RBText::Formatting.reset
end

Instance Method Details

#*(n) ⇒ Object



81
82
83
# File 'lib/rbtext/ftext.rb', line 81

def *(n)
  self.to_s*n
end

#+(str) ⇒ Object



73
74
75
# File 'lib/rbtext/ftext.rb', line 73

def +(str)
  self.to_s + str
end

#[](num) ⇒ Object



77
78
79
# File 'lib/rbtext/ftext.rb', line 77

def [](num)
  self.to_s[num]
end

#include?(i) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/rbtext/ftext.rb', line 85

def include?(i)
  self.to_s.include?(i)
end

#normal_textObject



65
66
67
# File 'lib/rbtext/ftext.rb', line 65

def normal_text
  @original_text.gsub(/\_\.([a-z]){1,2}\:([a-z\-])+\.\_/, "")
end

#original_textObject



69
70
71
# File 'lib/rbtext/ftext.rb', line 69

def original_text
  @original_text
end

#to_sObject



61
62
63
# File 'lib/rbtext/ftext.rb', line 61

def to_s
  @text
end