Module: VMCStringExtensions

Included in:
String
Defined in:
lib/cli/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/cli/core_ext.rb', line 99

def blank?
  self =~ /^\s*$/
end

#boldObject



87
88
89
# File 'lib/cli/core_ext.rb', line 87

def bold
  colorize("\e[0m\e[1m")
end

#colorize(color_code) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/cli/core_ext.rb', line 91

def colorize(color_code)
  if VMC::Cli::Config.colorize
    "#{color_code}#{self}\e[0m"
  else
    self
  end
end

#greenObject



79
80
81
# File 'lib/cli/core_ext.rb', line 79

def green
  colorize("\e[0m\e[32m")
end

#redObject



75
76
77
# File 'lib/cli/core_ext.rb', line 75

def red
  colorize("\e[0m\e[31m")
end

#truncate(limit = 30) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/cli/core_ext.rb', line 103

def truncate(limit = 30)
  return "" if self.blank?
  etc = "..."
  stripped = self.strip[0..limit]
  if stripped.length > limit
    stripped.gsub(/\s+?(\S+)?$/, "") + etc
  else
    stripped
  end
end

#yellowObject



83
84
85
# File 'lib/cli/core_ext.rb', line 83

def yellow
  colorize("\e[0m\e[33m")
end