Module: Cliprompt
- Defined in:
- lib/cliprompt.rb,
lib/cliprompt/version.rb,
lib/cliprompt/optionset.rb
Defined Under Namespace
Classes: OptionException, Optionset
Constant Summary collapse
- MSG_MANDATORY_TEXT =
"Sorry you need to fill that information."
- MSG_YES_OR_NO =
"You need to answer by yes, no, y, n, 1 or 0."
- MSG_CHOSE_IN_LIST =
"You need to chose between the available options."
- MSG_INPUT_A_NUMBER =
"You need input a number."
- MSG_CHOSE_A_NUMBER =
"Choose a number:"
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.ask(question, *options) ⇒ Object
interactive setup of option.
-
.guess(env, question, *options) ⇒ Object
if environment var is set, use it, otherwise, ask for a value.
-
.input ⇒ Object
defaults to STDIN.
-
.output ⇒ Object
defaults to STDOUT.
-
.say(message) ⇒ Object
output a message message - string to output.
-
.setio(input, output) ⇒ Object
makes possible to set input and output.
-
.shout(message) ⇒ Object
paints a message in bold and red and output it message - string to paint.
Class Method Details
.ask(question, *options) ⇒ Object
interactive setup of option
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cliprompt.rb', line 17 def ask(question, *) if [0].class == Optionset opts = [0] else opts = Optionset.new(*) end output.print "#{question} #{opts.display}" answer = input.gets.chomp output.flush opts.validate(question, answer) end |
.guess(env, question, *options) ⇒ Object
if environment var is set, use it, otherwise, ask for a value
30 31 32 33 34 35 36 37 |
# File 'lib/cliprompt.rb', line 30 def guess(env, question, *) opts = Optionset.new(*) if ENV[env] opts.validate(question, ENV[env]) else ask question, opts end end |
.input ⇒ Object
defaults to STDIN
58 59 60 |
# File 'lib/cliprompt.rb', line 58 def input @@input ||= STDIN end |
.output ⇒ Object
defaults to STDOUT
63 64 65 |
# File 'lib/cliprompt.rb', line 63 def output @@output ||= STDOUT end |
.say(message) ⇒ Object
output a message message - string to output
41 42 43 |
# File 'lib/cliprompt.rb', line 41 def say() output.puts end |
.setio(input, output) ⇒ Object
makes possible to set input and output
52 53 54 55 |
# File 'lib/cliprompt.rb', line 52 def setio(input, output) @@input = input @@output = output end |
.shout(message) ⇒ Object
paints a message in bold and red and output it message - string to paint
47 48 49 |
# File 'lib/cliprompt.rb', line 47 def shout() output.puts Paint[, :bold, :red ] end |