Class: MakeMenu::Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/make_menu/menu.rb

Overview

This class builds and displays a number-selection menu from a Makefile then prompts for a number and executes the target.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(makefile) ⇒ Menu

Returns a new instance of Menu.

Parameters:

  • makefile (String)

    Makefile name



12
13
14
15
16
17
# File 'lib/make_menu/menu.rb', line 12

def initialize(makefile)
  @groups = []
  @items = []
  @status_present = false
  build makefile
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



19
20
21
# File 'lib/make_menu/menu.rb', line 19

def groups
  @groups
end

#itemsObject (readonly)

Returns the value of attribute items.



19
20
21
# File 'lib/make_menu/menu.rb', line 19

def items
  @items
end

#status_presentObject

Returns the value of attribute status_present.



20
21
22
# File 'lib/make_menu/menu.rb', line 20

def status_present
  @status_present
end

Instance Method Details

#display_headerObject

Display the company logo and the status bar (if set)



49
50
51
52
# File 'lib/make_menu/menu.rb', line 49

def display_header
  puts  if 
  puts `make status` if status_present
end

#runObject

Display menu and prompt for command rubocop:disable Metrics/MethodLength



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/make_menu/menu.rb', line 24

def run
  running = true

  while running
    system 'clear' if clear_screen?

    display_header

    puts colorize(TextTable.new(groups).to_s)
    puts
    puts 'Press ENTER to quit'.align(:center).bold
    puts
    print 'Select option: '.align(:center)

    running = false unless execute_option(gets.strip)
  end

  puts

  system 'clear' if clear_screen?
end