class String
Public Instance Methods
truncate(truncate_at, options = {})
click to toggle source
taken from rails
# File lib/tarkin_commands.rb, line 3 def truncate(truncate_at, options = {}) s = self.gsub(/\r\n/, ' ') return s unless length > truncate_at omission = options[:omission] || '...' length_with_room_for_omission = truncate_at - omission.length stop = if options[:separator] rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission else length_with_room_for_omission end "#{s[0, stop]}#{omission}" end