Class: Digipolitan::UI
- Inherits:
-
Object
- Object
- Digipolitan::UI
- Defined in:
- lib/digipolitan-apps-tools/ui.rb
Class Method Summary collapse
- .confirm(msg) ⇒ Object
- .crash(msg) ⇒ Object
- .error(msg) ⇒ Object
- .input(msg) ⇒ Object
- .message(msg, color = nil) ⇒ Object
- .select(msg, values) ⇒ Object
- .success(msg) ⇒ Object
Class Method Details
.confirm(msg) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/digipolitan-apps-tools/ui.rb', line 29 def self.confirm(msg) self.("#{msg} (y/n)", :yellow) while c = $stdin.getch() if c == "y" return true elsif c == "n" return false else self.error("Select yes or no only") end end end |
.crash(msg) ⇒ Object
56 57 58 |
# File 'lib/digipolitan-apps-tools/ui.rb', line 56 def self.crash(msg) abort("\n[!!!] CRASH : #{msg}".colorize(:red)) end |
.error(msg) ⇒ Object
25 26 27 |
# File 'lib/digipolitan-apps-tools/ui.rb', line 25 def self.error(msg) self.("\n[!] ERROR : #{msg}", :red) end |
.input(msg) ⇒ Object
20 21 22 23 |
# File 'lib/digipolitan-apps-tools/ui.rb', line 20 def self.input(msg) self.(msg, :yellow) return $stdin.gets().strip() end |
.message(msg, color = nil) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/digipolitan-apps-tools/ui.rb', line 7 def self.(msg, color = nil) if color != nil msg = msg.colorize(color) else msg = "#{msg}\n" end $stdout.puts(msg) end |
.select(msg, values) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/digipolitan-apps-tools/ui.rb', line 42 def self.select(msg, values) self.(msg) i = 0 values.each { |value| i += 1 self.("#{i} - #{value}") } while val = self.input("Select a value between [1 - #{i}]").to_i if val >= 1 && val <= i return values[val-1] end end end |
.success(msg) ⇒ Object
16 17 18 |
# File 'lib/digipolitan-apps-tools/ui.rb', line 16 def self.success(msg) self.(msg, :green) end |