Class: RVM::Classes::String
- Inherits:
-
String
- Object
- String
- RVM::Classes::String
show all
- Extended by:
- Plugin
- Defined in:
- lib/rvm/classes/string.rb
Constant Summary
collapse
- ANSI_MAP =
{
'h' => 1, 'H' => 22,
'u' => 4, 'U' => 24,
'f' => 5, 'f' => 25,
'i' => 7, 'I' => 27,
'n' => 0,
'x' => 30, 'X' => 40,
'r' => 31, 'R' => 41,
'g' => 32, 'G' => 42,
'y' => 33, 'Y' => 42,
'b' => 34, 'B' => 44,
'm' => 35, 'M' => 45,
'c' => 36, 'C' => 45,
'w' => 37, 'W' => 47,
}
- @@type =
:string
Instance Method Summary
collapse
Methods included from Plugin
helper, included, plugin_host, plugin_id, register_for
Constructor Details
#initialize(val = "") ⇒ String
Returns a new instance of String.
24
25
26
|
# File 'lib/rvm/classes/string.rb', line 24
def initialize val = ""
super val.to_s
end
|
Instance Method Details
62
63
64
65
|
# File 'lib/rvm/classes/string.rb', line 62
def + v
v = v.to_s if not v.is_a?(String)
self.class.new(super(v))
end
|
#ansi(colorset) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/rvm/classes/string.rb', line 67
def ansi colorset
colorset.gsub!(/[^#{ANSI_MAP.keys.join('')}]/,'')
colorcode = colorset.split('').map { |c| ANSI_MAP[c].to_s}.join(';')
c = "\e[#{colorcode}m"
self.class.new("#{c}#{self.gsub("\e[0m",c)}\e[0m")
end
|
#center(width, char = " ") ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/rvm/classes/string.rb', line 36
def center width, char = " "
c = char[0..0]
c = ' ' if c.empty?
width = width.to_i - self.length
width = 0 if width < 0
l = width / 2
r = width - l
self.class.new((c*l) + self + (c*r))
end
|
#data_type ⇒ Object
32
33
34
|
# File 'lib/rvm/classes/string.rb', line 32
def data_type
:string
end
|
28
29
30
|
# File 'lib/rvm/classes/string.rb', line 28
def is_true?
not empty?
end
|
#ljust(width, char = " ") ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/rvm/classes/string.rb', line 46
def ljust width, char = " "
c = char[0..0]
c = ' ' if c.empty?
width = width.to_i - self.length
width = 0 if width < 0
self.class.new(self + (c*width))
end
|
#rjust(width, char = " ") ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/rvm/classes/string.rb', line 54
def rjust width, char = " "
c = char[0..0]
c = ' ' if c.empty?
width = width.to_i - self.length
width = 0 if width < 0
self.class.new((c*width) + self)
end
|
74
75
76
|
# File 'lib/rvm/classes/string.rb', line 74
def value
to_s
end
|