class Main
Attributes
manual_edit[RW]
Public Class Methods
new()
click to toggle source
# File lib/main.rb, line 10 def initialize @manual_edit = VimEdit.new end
Public Instance Methods
replace_all()
click to toggle source
# 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
Private Instance Methods
get_root_path()
click to toggle source
# File lib/main.rb, line 48 def get_root_path search_root_input = gets.chomp until valid_path?(search_root_input) puts "That path doesn't exist, buddy. Hit me again" search_root_input = gets.chomp end if search_root_input.empty? puts "Defaulting to current directory. Hit return to begin" gets return "." end return search_root_input end
prompt_search_details()
click to toggle source
# File lib/main.rb, line 37 def prompt_search_details puts "We will be replacing some text today." puts "What is a pattern describing the text you want to replace?" pattern = gets.chomp puts "" puts "What is root of your search? ('.' would probably work fine)" root_path = get_root_path puts "" [pattern, root_path] end
record_manual_replacement!(replacement_collection, old_contents, file_line)
click to toggle source
# File lib/main.rb, line 68 def record_manual_replacement!(replacement_collection, old_contents, file_line) new_contents = file_line.raw_contents replacement_collection << Replacement.generate(old_contents, new_contents) unless old_contents == new_contents replacement_collection end
take_user_suggestion!(replacement, file_line)
click to toggle source
# File lib/main.rb, line 74 def take_user_suggestion!(replacement, file_line) new_contents = replacement.suggest(file_line.raw_contents) file_line.update_filesystem!(new_contents) end
valid_path?(path_input)
click to toggle source
# File lib/main.rb, line 64 def valid_path?(path_input) File.exist?(path_input) || path_input.empty? end