Method: VMCStringExtensions#truncate

Defined in:
lib/cli/core_ext.rb

#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