Class: ReplaceDocument

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_file, temp_file) ⇒ ReplaceDocument

Returns a new instance of ReplaceDocument.



6
7
8
9
# File 'lib/replace_it.rb', line 6

def initialize(original_file, temp_file)
  @original_file = original_file
  @temp_file     = temp_file
end

Instance Attribute Details

#original_fileObject

Returns the value of attribute original_file.



4
5
6
# File 'lib/replace_it.rb', line 4

def original_file
  @original_file
end

#temp_fileObject

Returns the value of attribute temp_file.



4
5
6
# File 'lib/replace_it.rb', line 4

def temp_file
  @temp_file
end

Instance Method Details

#document_replace(string, new_string) ⇒ Object



11
12
13
14
15
# File 'lib/replace_it.rb', line 11

def document_replace(string, new_string)
  File.open(@temp_file, 'w') do |file|
    file.puts File.read(@original_file).gsub(/#{string}/, new_string)
  end
end