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
prompt() click to toggle source
# File lib/menuboy.rb, line 143
def prompt
  print "(#{@name})> "
end