Class: Torba::Ui
- Inherits:
-
Object
- Object
- Torba::Ui
- Defined in:
- lib/torba/ui.rb
Overview
Thin wrapper around Thor::Shell.
Instance Method Summary collapse
- #choose_one(options) ⇒ Integer?
- #confirm(message) ⇒ Object
- #error(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize ⇒ Ui
constructor
A new instance of Ui.
- #suggest(message) ⇒ Object
Constructor Details
#initialize ⇒ Ui
Returns a new instance of Ui.
6 7 8 |
# File 'lib/torba/ui.rb', line 6 def initialize @shell = Thor::Base.shell.new end |
Instance Method Details
#choose_one(options) ⇒ Integer?
29 30 31 32 33 34 35 36 37 |
# File 'lib/torba/ui.rb', line 29 def choose_one() .each_with_index do |option, index| info("#{index + 1} : #{option}") end info("0 : - exit -") index = @shell.ask("> ").to_i - 1 (0...size - 1).cover?(index) ? index : nil end |
#confirm(message) ⇒ Object
14 15 16 |
# File 'lib/torba/ui.rb', line 14 def confirm() @shell.say(, :green) end |
#error(message) ⇒ Object
22 23 24 |
# File 'lib/torba/ui.rb', line 22 def error() @shell.say(, :red) end |
#info(message) ⇒ Object
10 11 12 |
# File 'lib/torba/ui.rb', line 10 def info() @shell.say() end |
#suggest(message) ⇒ Object
18 19 20 |
# File 'lib/torba/ui.rb', line 18 def suggest() @shell.say(, :yellow) end |