Class: Hedgelog::ScrubReplacement

Inherits:
Object
  • Object
show all
Defined in:
lib/hedgelog/scrub_replacement.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, replacement) ⇒ ScrubReplacement

Returns a new instance of ScrubReplacement.



3
4
5
6
7
# File 'lib/hedgelog/scrub_replacement.rb', line 3

def initialize(key, replacement)
  @key = key
  @replacement = replacement
  @match_regex = /("?)#{@key}("?[=:]\s*"?)(.+?)(["&,;\s]|$)/
end

Instance Method Details

#scrub_array(array) ⇒ Object



25
26
27
28
29
# File 'lib/hedgelog/scrub_replacement.rb', line 25

def scrub_array(array)
  array.each do |val|
    scrub_thing(val)
  end
end

#scrub_hash(hash) ⇒ Object



18
19
20
21
22
23
# File 'lib/hedgelog/scrub_replacement.rb', line 18

def scrub_hash(hash)
  hash.each do |key, val|
    next hash[key] = @replacement if key.to_s.casecmp(@key.to_s).zero?
    scrub_thing(val)
  end
end

#scrub_string(string) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/hedgelog/scrub_replacement.rb', line 9

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}"
  end
end