Module: Todos::Menu

Included in:
Commands::BasicTaskManipulation, Commands::GeneralCommands
Defined in:
lib/todos_cli.rb

Class Method Summary collapse

Class Method Details

.append_features(klass) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/todos_cli.rb', line 21

def self.append_features(klass)
  def klass.menu
    @commands ||= constants.reject{ |command| command =~ /basic/i }.collect { |command| const_get(command).extend(MenuItem) }.sort { |a, b| a::KEY <=> b::KEY }
    print_menu
    process_user_input
  end
  def klass.print_menu
    puts
    @commands.each do |command|
      puts command.menu_item
    end
  end
  def klass.process_user_input
    print 'Command:_ '
    user_input = gets.strip.downcase
    puts
    command = @commands.detect { |command| command::KEY.eql? user_input }
    call_command(command) if command
  end
end