Class: Hedgelog::ScrubReplacement
- Inherits:
-
Object
- Object
- Hedgelog::ScrubReplacement
- Defined in:
- lib/hedgelog/scrub_replacement.rb
Instance Method Summary collapse
-
#initialize(key, replacement) ⇒ ScrubReplacement
constructor
A new instance of ScrubReplacement.
- #scrub_array(array) ⇒ Object
- #scrub_hash(hash) ⇒ Object
- #scrub_string(string) ⇒ Object
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}\1(=>|=|:)(\s*)("?)(.+?)\4(&|,|;|\s|$)/ end |
Instance Method Details
#scrub_array(array) ⇒ Object
28 29 30 31 32 |
# File 'lib/hedgelog/scrub_replacement.rb', line 28 def scrub_array(array) array.each do |val| scrub_thing(val) end end |
#scrub_hash(hash) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/hedgelog/scrub_replacement.rb', line 20 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 17 18 |
# File 'lib/hedgelog/scrub_replacement.rb', line 9 def scrub_string(string) string.gsub!(@match_regex) do 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 |