Class: Approvals::Scrubber
- Inherits:
-
Object
- Object
- Approvals::Scrubber
- Defined in:
- lib/approvals/scrubber.rb
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(string, hash = nil) ⇒ Scrubber
constructor
A new instance of Scrubber.
- #scrub(string) ⇒ Object
- #to_s ⇒ Object
- #unscrub(string = @string) ⇒ Object
- #wrap(string) ⇒ Object
Constructor Details
#initialize(string, hash = nil) ⇒ Scrubber
Returns a new instance of 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
#hash ⇒ Object
8 9 10 11 12 |
# File 'lib/approvals/scrubber.rb', line 8 def hash @hash ||= { 'current_dir' => File.('.') } 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_s ⇒ Object
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 |