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.



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

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.



77
78
79
# File 'lib/pve/helper.rb', line 77

def color_codes
  @color_codes
end

#stringObject (readonly)

Returns the value of attribute string.



77
78
79
# File 'lib/pve/helper.rb', line 77

def string
  @string
end

Instance Method Details

#<=>(o) ⇒ Object



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

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

#inspectObject



83
84
85
# File 'lib/pve/helper.rb', line 83

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

#lengthObject Also known as: size



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

def length() @string.length end

#to_sObject Also known as: to_str



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

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