Module: GBud::UserPrompt

Defined in:
lib/gbud/user_prompt.rb

Overview

UserPrompt

Author

Richard Davis

Copyright

Copyright 2017 Richard Davis

License

GNU Public License 3

Module containing methods used to prompt the user for program input.

Class Method Summary collapse

Class Method Details

.confirm_inputObject

Confirms the value entered by the user



51
52
53
54
55
56
57
58
# File 'lib/gbud/user_prompt.rb', line 51

def self.confirm_input
  puts "You have entered: #{@value}"
  print 'Is this correct? (Y/N) => '
  confirm = gets.chomp.to_s.upcase
  return false unless confirm == 'Y'

  true
end

.get_value(prompt) ⇒ Object

Returns the value entered by the user



34
35
36
37
# File 'lib/gbud/user_prompt.rb', line 34

def self.get_value(prompt)
  prompt_user prompt
  @value
end

.prompt_user(prompt) ⇒ Object

Prompts the user for a value



41
42
43
44
45
46
47
# File 'lib/gbud/user_prompt.rb', line 41

def self.prompt_user(prompt)
  loop do
    print prompt
    @value = gets.chomp.to_s
    break if confirm_input
  end
end