lib/gorillib/string/truncate.rb in gorillib-0.0.7 vs lib/gorillib/string/truncate.rb in gorillib-0.0.8

- old
+ new

@@ -14,16 +14,16 @@ # # "And they found that many people were sleeping better.".truncate(25, :omission => "... (continued)") # # => "And they f... (continued)" def truncate(length, options = {}) text = self.dup - chars = text.respond_to?(:mb_chars) ? text.mb_chars : text.chars + chars = text.respond_to?(:mb_chars) ? text.mb_chars : text omission = options[:omission] || "..." omission_len = omission.respond_to?(:mb_chars) ? omission.mb_chars.length : omission.length length_with_room_for_omission = length - omission_len if (separator = options[:separator]) - separator_chars = separator.respond_to?(:mb_chars) ? separator.to_s.mb_chars : separator.to_s.chars + separator_chars = separator.respond_to?(:mb_chars) ? separator.to_s.mb_chars : separator.to_s stop = chars.rindex(separator_chars, length_with_room_for_omission) || length_with_room_for_omission else stop = length_with_room_for_omission end