lib/lite/ruby/string.rb in lite-ruby-1.0.2 vs lib/lite/ruby/string.rb in lite-ruby-1.0.3
- old
+ new
@@ -322,10 +322,35 @@
def pop
self[-1]
end
+ def non_possessive
+ dup.non_possessive!
+ end
+
+ def non_possessive!
+ return self unless possessive?
+
+ chomp!("'s") || chomp!("'") || self
+ end
+
+ def possessive
+ return self if possessive?
+
+ possession = end_with?('s') ? "'" : "'s"
+ "#{self}#{possession}"
+ end
+
+ def possessive!
+ replace(possessive)
+ end
+
+ def possessive?
+ %w['s s'].any? { |pos| end_with?(pos) }
+ end
+
def push(string)
replace(concat(string))
end
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
@@ -512,10 +537,10 @@
end
def truncate_words(words_count, options = {})
sep = options[:separator] || /\s+/
sep = Regexp.escape(sep.to_s) unless sep.is_a(Regexp)
- return self unless self =~ /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m
+ return self unless /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m.match?(self)
"#{::Regexp.last_match(1)}#{options[:omissio] || '...'}"
end
def underscore