Class: Torba::Ui

Inherits:
Object
  • Object
show all
Defined in:
lib/torba/ui.rb

Overview

Thin wrapper around Thor::Shell.

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initializeUi

Returns a new instance of Ui.

Since:

  • 0.1.0



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?

Returns:

  • (Integer)

    index of chosen option.

  • (nil)

    if exit was chosen.

Since:

  • 0.7.0



29
30
31
32
33
34
35
36
37
# File 'lib/torba/ui.rb', line 29

def choose_one(options)
  options.each_with_index do |option, index|
    info("#{index + 1} : #{option}")
  end
  info("0 : - exit -")

  index = @shell.ask("> ").to_i - 1
  (0..options.size - 1).cover?(index) ? index : nil
end

#confirm(message) ⇒ Object

Since:

  • 0.1.0



14
15
16
# File 'lib/torba/ui.rb', line 14

def confirm(message)
  @shell.say(message, :green)
end

#error(message) ⇒ Object

Since:

  • 0.1.0



22
23
24
# File 'lib/torba/ui.rb', line 22

def error(message)
  @shell.say(message, :red)
end

#info(message) ⇒ Object

Since:

  • 0.1.0



10
11
12
# File 'lib/torba/ui.rb', line 10

def info(message)
  @shell.say(message)
end

#suggest(message) ⇒ Object

Since:

  • 0.1.0



18
19
20
# File 'lib/torba/ui.rb', line 18

def suggest(message)
  @shell.say(message, :yellow)
end