lib/cliutils/ext/string_extensions.rb in cliutils-2.2.4 vs lib/cliutils/ext/string_extensions.rb in cliutils-2.2.5
- old
+ new
@@ -53,9 +53,17 @@
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z])([A-Z])/, '\1_\2').
downcase
end
+ # Truncates a string to a certain length
+ # and adds an ellipsis after.
+ # @param [Fixnum] length The length to truncate at
+ # @return [String]
+ def truncate(length = 30)
+ self[0..length].gsub(/\s\w+\s*$/, '...')
+ end
+
# Makes the associated string white.
# @return [void]
def white
colorize(37)
end