class ChangePrompt
Constants
- HORIZONTAL_LINE
- LINES_OF_CONTEXT
- USE_EDITOR
Attributes
replacements[R]
user_input[R]
Public Class Methods
get_the_input(replacements)
click to toggle source
# File lib/change_prompt.rb, line 23 def self.get_the_input(replacements) user_input = gets puts("") prompt = ChangePrompt.new(user_input, replacements) until(prompt.valid?) puts "Yo, #{prompt.instance_variable_get(:@user_input)} is not a good answer. Try again" user_input = gets puts("") prompt = ChangePrompt.new(user_input, replacements) end prompt end
new(user_input, replacements)
click to toggle source
# File lib/change_prompt.rb, line 38 def initialize(user_input, replacements) @user_input = user_input @replacements = replacements end
prompt(pattern, file_line, replacements)
click to toggle source
# File lib/change_prompt.rb, line 11 def self.prompt(pattern, file_line, replacements) present_line(file_line, pattern) puts("How would you like to update the above line? Options below. Hit return to do nothing\n\n") puts HORIZONTAL_LINE puts("#{USE_EDITOR}: Edit in Vi") replacements.each_with_index do |replacement, index| puts "#{one_indexed(index)}: #{replacement.highlighted_suggest(file_line.raw_contents)}" end puts HORIZONTAL_LINE get_the_input(replacements) end
Private Class Methods
one_indexed(index)
click to toggle source
# File lib/change_prompt.rb, line 73 def self.one_indexed(index) index + 1 end
present_line(file_line, pattern)
click to toggle source
# File lib/change_prompt.rb, line 77 def self.present_line(file_line, pattern) puts "\n" * 50 puts HORIZONTAL_LINE puts("FILENAME: #{file_line.path}") puts HORIZONTAL_LINE puts(FileLinePresenter.present_contents(file_line, pattern, LINES_OF_CONTEXT)) puts HORIZONTAL_LINE puts "\n" end
Public Instance Methods
chose_editor?()
click to toggle source
# File lib/change_prompt.rb, line 43 def chose_editor? user_input.downcase.match(USE_EDITOR.downcase) end
selected_replacement()
click to toggle source
# File lib/change_prompt.rb, line 47 def selected_replacement replacements[zero_indexed(integer_input)] if integer_input end
valid?()
click to toggle source
# File lib/change_prompt.rb, line 51 def valid? chose_editor? || valid_integer_input || user_input.chomp.empty? end
Private Instance Methods
integer_input()
click to toggle source
# File lib/change_prompt.rb, line 59 def integer_input Integer(user_input) rescue => e nil end
valid_integer_input()
click to toggle source
# File lib/change_prompt.rb, line 69 def valid_integer_input (1..replacements.count).include?(integer_input) end
zero_indexed(index)
click to toggle source
# File lib/change_prompt.rb, line 65 def zero_indexed(index) index - 1 end