Class: Approvals::Scrubber

Inherits:
Object
  • Object
show all
Defined in:
lib/approvals/scrubber.rb

Instance Method Summary collapse

Constructor Details

#initialize(string, hash = nil) ⇒ Scrubber


3
4
5
6
# File 'lib/approvals/scrubber.rb', line 3

def initialize(string, hash = nil)
  @hash = hash
  @string = scrub(string)
end

Instance Method Details

#hashObject


8
9
10
11
12
# File 'lib/approvals/scrubber.rb', line 8

def hash
  @hash ||= {
    'current_dir' => File.expand_path('.')
  }
end

#scrub(string) ⇒ Object


14
15
16
17
18
19
# File 'lib/approvals/scrubber.rb', line 14

def scrub(string)
  hash.each do |key, value|
    string = string.gsub(value, wrap(key))
  end
  string
end

#to_sObject


32
33
34
# File 'lib/approvals/scrubber.rb', line 32

def to_s
  @string
end

#unscrub(string = @string) ⇒ Object


21
22
23
24
25
26
# File 'lib/approvals/scrubber.rb', line 21

def unscrub(string = @string)
  hash.each do |key, value|
    string = string.gsub(wrap(key), value)
  end
  string
end

#wrap(string) ⇒ Object


28
29
30
# File 'lib/approvals/scrubber.rb', line 28

def wrap(string)
  "{{#{string}}}"
end