class Coals::Menu
Attributes
selection[R]
Public Class Methods
new(options:, prompt: nil, title: '')
click to toggle source
Show a menu of options in a loop until the user makes a selection. Return the selection value
@param menu {Array} - list of options to choose from
# File lib/coals/menu.rb, line 10 def initialize(options:, prompt: nil, title: '') @select = nil @options = options @title = title @prompt = prompt show_menu until @selection end
Private Instance Methods
integer_input()
click to toggle source
# File lib/coals/menu.rb, line 27 def integer_input print "\nChoose an option: ".bold option_index = raw_input.to_i - 1 @selection = @options.values[option_index] end
min_column_width()
click to toggle source
# File lib/coals/menu.rb, line 46 def min_column_width @options.keys.max_by(&:length).length end
print(str)
click to toggle source
# File lib/coals/menu.rb, line 42 def print(str) $stdout.print str end
println(str)
click to toggle source
# File lib/coals/menu.rb, line 38 def println(str) $stdout.puts str end
raw_input()
click to toggle source
# File lib/coals/menu.rb, line 33 def raw_input input = $stdin.gets.chomp input =~ /quit|exit|q/ ? abort('Goodbye 👋') : input end