Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/tarkin_commands.rb
Instance Method Summary collapse
-
#truncate(truncate_at, options = {}) ⇒ Object
taken from rails.
Instance Method Details
#truncate(truncate_at, options = {}) ⇒ Object
taken from rails
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/tarkin_commands.rb', line 3 def truncate(truncate_at, = {}) s = self.gsub(/\r\n/, ' ') return s 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 "#{s[0, stop]}#{omission}" end |