lib/sub_diff/gsub.rb in sub_diff-1.1.0 vs lib/sub_diff/gsub.rb in sub_diff-1.1.1
- old
+ new
@@ -1,10 +1,16 @@
module SubDiff
+ # Processes matches for {String#gsub} replacements
+ # by pushing diffs into a {Builder} instance.
+ #
+ # Used internally by {Adapter}.
+ #
+ # @api private
class Gsub < Sub
private
- def process(_builder, diff, _search)
+ def append_diff_to_builder(diff, _search)
super
last_prefix << prefix(diff) << diff[:match]
end
def last_prefix
@@ -15,15 +21,10 @@
super.sub(last_prefix, '')
end
def suffix(_diff, search)
suffix = super
- matcher = suffix_matcher(search)
- skip_suffix = suffix.send(matcher, search)
- suffix unless skip_suffix
- end
-
- def suffix_matcher(search)
- search.is_a?(Regexp) ? :match : :include?
+ regex = Regexp.new(search)
+ suffix unless suffix.match(regex)
end
end
end