Class: MakeMenu::MenuItem
- Inherits:
-
Object
- Object
- MakeMenu::MenuItem
- Defined in:
- lib/make_menu/menu_item.rb
Overview
This class represents an option in the menu which runs a target from the Makefile
Constant Summary collapse
- INDENT =
6
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#option_number ⇒ Object
readonly
Returns the value of attribute option_number.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(option_number = nil, target = nil, description = nil) ⇒ MenuItem
constructor
A new instance of MenuItem.
-
#to_s ⇒ String
Text to display for this item.
-
#width ⇒ Integer
Number of characters required to display the item.
Constructor Details
#initialize(option_number = nil, target = nil, description = nil) ⇒ MenuItem
Returns a new instance of MenuItem.
8 9 10 11 12 |
# File 'lib/make_menu/menu_item.rb', line 8 def initialize(option_number = nil, target = nil, description = nil) @option_number = option_number @target = target @description = description || target end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
14 15 16 |
# File 'lib/make_menu/menu_item.rb', line 14 def description @description end |
#option_number ⇒ Object (readonly)
Returns the value of attribute option_number.
14 15 16 |
# File 'lib/make_menu/menu_item.rb', line 14 def option_number @option_number end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
14 15 16 |
# File 'lib/make_menu/menu_item.rb', line 14 def target @target end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/make_menu/menu_item.rb', line 16 def execute cmd = ['make', target] puts "> #{cmd.join(' ').cyan}\n" unless system(*cmd) # Indicates the command failed, so we pause to allow user to see error message puts "\nPress ENTER to continue....".dark gets end rescue StandardError => _e # Sink keyboard interrupt from within Make target end |
#to_s ⇒ String
Returns Text to display for this item.
34 35 36 |
# File 'lib/make_menu/menu_item.rb', line 34 def to_s "#{option_number.to_s.rjust(INDENT, ' ').bold}. #{description}" end |
#width ⇒ Integer
Returns Number of characters required to display the item.
29 30 31 |
# File 'lib/make_menu/menu_item.rb', line 29 def width description.size + INDENT + 1 end |