Class: ColoredString

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/pve/helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, color_codes) ⇒ ColoredString

Returns a new instance of ColoredString.



65
66
67
# File 'lib/pve/helper.rb', line 65

def initialize string, color_codes
  @string, @color_codes = string, color_codes
end

Instance Attribute Details

#color_codesObject (readonly)

Returns the value of attribute color_codes.



63
64
65
# File 'lib/pve/helper.rb', line 63

def color_codes
  @color_codes
end

#stringObject (readonly)

Returns the value of attribute string.



63
64
65
# File 'lib/pve/helper.rb', line 63

def string
  @string
end

Instance Method Details

#<=>(o) ⇒ Object



81
# File 'lib/pve/helper.rb', line 81

def <=>(o) @string <=> o.string end

#inspectObject



69
70
71
# File 'lib/pve/helper.rb', line 69

def inspect
  "#<ColoredString #{@color_codes} #{@string.inspect}>"
end

#lengthObject Also known as: size



73
# File 'lib/pve/helper.rb', line 73

def length() @string.length end

#to_sObject Also known as: to_str

def to_str() self end



76
# File 'lib/pve/helper.rb', line 76

def to_s() "\e[#{@color_codes}m#{@string}\e[0m" end