lib/hedgelog/scrub_replacement.rb in hedgelog-0.1.11 vs lib/hedgelog/scrub_replacement.rb in hedgelog-0.1.12
- old
+ new
@@ -1,18 +1,20 @@
class Hedgelog
class ScrubReplacement
def initialize(key, replacement)
@key = key
@replacement = replacement
- @match_regex = /("?)#{@key}("?[=:]\s*"?)(.+?)(["&,;\s]|$)/
+ @match_regex = /("?)#{@key}\1(=>|=|:)(\s*)("?)(.+?)\4(&|,|;|\s|$)/
end
def scrub_string(string)
string.gsub!(@match_regex) do
- start = Regexp.last_match[1]
- eql = Regexp.last_match[2]
- delim = Regexp.last_match[4]
- "#{start}#{@key}#{eql}#{@replacement}#{delim}"
+ quote1 = Regexp.last_match[1]
+ sep = Regexp.last_match[2]
+ whitespace = Regexp.last_match[3]
+ quote2 = Regexp.last_match[4]
+ rest = Regexp.last_match[6]
+ "#{quote1}#{@key}#{quote1}#{sep}#{whitespace}#{quote2}#{@replacement}#{quote2}#{rest}"
end
end
def scrub_hash(hash)
hash.each do |key, val|