Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/utils.rb
Overview
Pulled from ActionSupport.
Instance Method Summary collapse
Instance Method Details
#at_width(width) ⇒ Object
52 53 54 |
# File 'lib/utils.rb', line 52 def at_width(width) truncate(width).ljust(width) end |
#truncate(truncate_at, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/utils.rb', line 37 def truncate(truncate_at, = {}) return dup unless length > truncate_at omission = [:omission] || '...' length_with_room_for_omission = truncate_at - omission.length stop = \ if [:separator] rindex([:separator], length_with_room_for_omission) || length_with_room_for_omission else length_with_room_for_omission end "#{self[0, stop]}#{omission}" end |