class String
Pulled from ActionSupport.
Public Instance Methods
at_width(width)
click to toggle source
# File lib/utils.rb, line 52 def at_width(width) truncate(width).ljust(width) end
truncate(truncate_at, options = {})
click to toggle source
# File lib/utils.rb, line 37 def truncate(truncate_at, options = {}) return dup 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 "#{self[0, stop]}#{omission}" end