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



49
50
51
52
53
54
55
# File 'lib/gbud/user_prompt.rb', line 49

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



32
33
34
35
# File 'lib/gbud/user_prompt.rb', line 32

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

.prompt_user(prompt) ⇒ Object

Prompts the user for a value



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

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