class Menuboy::Menu
Constants
- CTRL_C
Attributes
name[RW]
options[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/menuboy.rb, line 110 def initialize name self.name = name self.options = [] end
Public Instance Methods
handle_input(k)
click to toggle source
# File lib/menuboy.rb, line 129 def handle_input k if k == "h" print_help elsif k == "p" && defined? Pry Menuboy.fix_stdin do binding.pry end elsif option = option_match?(k) option.proc.call else puts "Unassigned input" end end
option_match?(input)
click to toggle source
# File lib/menuboy.rb, line 124 def option_match? input matches = self.options.select{|o| o.key == input} matches.length == 1 ? matches.last : false end
print_help()
click to toggle source
# File lib/menuboy.rb, line 115 def print_help self.options.each do |opt| puts "#{opt.key} - #{opt.name}" end puts "p - jump into a Pry repl" if defined? Pry puts "h - print help" puts "q - quit / go back" end
prompt()
click to toggle source
# File lib/menuboy.rb, line 143 def prompt print "(#{@name})> " end