class Digipolitan::UI
Public Class Methods
confirm(msg)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 34 def self.confirm(msg) self.message("#{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)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 61 def self.crash(msg) abort("\n[!!!] CRASH : #{msg}".colorize(:red)) end
error(msg)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 30 def self.error(msg) self.message("\n[!] ERROR : #{msg}", :red) end
input(msg)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 21 def self.input(msg) self.message(msg, :yellow) return $stdin.gets.strip end
message(msg, color = nil)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 8 def self.message(msg, color = nil) if color != nil msg = msg.colorize(color) else msg = "#{msg}\n" end $stdout.puts(msg) end
select(msg, values)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 47 def self.select(msg, values) self.message(msg) i = 0 values.each { |value| i += 1 self.message("#{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)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 17 def self.success(msg) self.message(msg, :green) end
warning(msg)
click to toggle source
# File lib/digipolitan-apps-tools/ui.rb, line 26 def self.warning(msg) self.message("\n[!] WARNING : #{msg}", :yellow) end