Class: Main

Inherits:
Object show all
Defined in:
lib/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMain

Returns a new instance of Main.



10
11
12
# File 'lib/main.rb', line 10

def initialize
  @manual_edit = VimEdit.new
end

Instance Attribute Details

#manual_editObject

Returns the value of attribute manual_edit.



8
9
10
# File 'lib/main.rb', line 8

def manual_edit
  @manual_edit
end

Instance Method Details

#replace_allObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/main.rb', line 14

def replace_all
  pattern, root_path = prompt_search_details

  file_lines = FileLine.find_all(pattern, root_path)
  replacement_collection = ReplacementCollection.new

  file_lines.each do |file_line|
    if file_line.raw_contents.match(pattern)
      old_contents = file_line.raw_contents
      applicable_replacements = replacement_collection.applicable_replacements(old_contents)
      user_input = ChangePrompt.prompt(pattern, file_line, applicable_replacements)
      if user_input.chose_editor?
        manual_edit.execute!(file_line, pattern)
        record_manual_replacement!(replacement_collection, old_contents, file_line)
      elsif user_input.selected_replacement
        take_user_suggestion!(user_input.selected_replacement, file_line)
      end
    end
  end
end