lib/lite/ruby/string.rb in lite-ruby-1.0.29 vs lib/lite/ruby/string.rb in lite-ruby-1.0.30

- old
+ new

@@ -161,12 +161,12 @@ def headerize! replace(headerize) end - def humanize(options = {}) - dup.humanize!(options) + def humanize(capitalize: true) + dup.humanize!(capitalize: capitalize) end def humanize!(capitalize: true) underscore! gsub!(/_id\z/, '') @@ -528,12 +528,13 @@ end def truncate(truncate_at, options = {}) return dup unless length > truncate_at - seperator = options[:separator] omission = options[:omission] || '...' + seperator = options[:separator] + size_with_room_for_omission = truncate_at - omission.length stop = if seperator rindex(seperator || '', size_with_room_for_omission) || size_with_room_for_omission else @@ -541,16 +542,20 @@ end "#{self[0, stop]}#{omission}" end + # rubocop:disable Layout/LineLength def truncate_words(words_count, options = {}) - sep = options[:separator] || /\s+/ - sep = Regexp.escape(sep.to_s) unless sep.is_a(Regexp) - return self unless /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m.match?(self) + omission = options[:omission] || '...' + seperator = options[:separator] || /\s+/ - "#{::Regexp.last_match(1)}#{options[:omissio] || '...'}" + seperator = Regexp.escape(seperator.to_s) unless seperator.is_a(Regexp) + return self unless /\A((?:.+?#{seperator}){#{words_count - 1}}.+?)#{seperator}.*/m.match?(self) + + "#{::Regexp.last_match(1)}#{omission}" end + # rubocop:enable Layout/LineLength def underscore dup.underscore! end