Class: GemMenu::Menu
- Inherits:
-
Object
- Object
- GemMenu::Menu
- Defined in:
- lib/gem_menu.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#menu_hash ⇒ Object
Returns the value of attribute menu_hash.
-
#parameter ⇒ Object
Returns the value of attribute parameter.
-
#previous_menu ⇒ Object
Returns the value of attribute previous_menu.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #display_menu ⇒ Object
- #exit_method ⇒ Object
-
#initialize(title, entries, optional_args = nil) ⇒ Menu
constructor
A new instance of Menu.
- #launch_selection(selection) ⇒ Object
- #menu_char_begin ⇒ Object
- #menu_char_end ⇒ Object
- #receive_input ⇒ Object
- #retreive_selection ⇒ Object
- #retrieve_selection ⇒ Object
- #set_choices ⇒ Object
Constructor Details
#initialize(title, entries, optional_args = nil) ⇒ Menu
Returns a new instance of Menu.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gem_menu.rb', line 48 def initialize(title, entries, optional_args=nil) self.title = title self.entries = entries if optional_args optional_args.each do |key, value| self.send("#{key}=", value) end end self. = {"x" => self.exit_method} self.set_choices end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
42 43 44 |
# File 'lib/gem_menu.rb', line 42 def entries @entries end |
#menu_hash ⇒ Object
Returns the value of attribute menu_hash.
42 43 44 |
# File 'lib/gem_menu.rb', line 42 def @menu_hash end |
#parameter ⇒ Object
Returns the value of attribute parameter.
42 43 44 |
# File 'lib/gem_menu.rb', line 42 def parameter @parameter end |
#previous_menu ⇒ Object
Returns the value of attribute previous_menu.
42 43 44 |
# File 'lib/gem_menu.rb', line 42 def @previous_menu end |
#title ⇒ Object
Returns the value of attribute title.
42 43 44 |
# File 'lib/gem_menu.rb', line 42 def title @title end |
Instance Method Details
#display_menu ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/gem_menu.rb', line 92 def puts puts "#{self.}#{self.title}#{self.}" .sort.to_h.each do |user_choice, description| puts "#{user_choice.colorize(:light_yellow)}) #{description}" end end |
#exit_method ⇒ Object
60 61 62 |
# File 'lib/gem_menu.rb', line 60 def exit_method @@exit end |
#launch_selection(selection) ⇒ Object
111 112 113 |
# File 'lib/gem_menu.rb', line 111 def launch_selection(selection) self.[selection].next_selection end |
#menu_char_begin ⇒ Object
64 65 66 |
# File 'lib/gem_menu.rb', line 64 def @@menu_char_begin end |
#menu_char_end ⇒ Object
68 69 70 |
# File 'lib/gem_menu.rb', line 68 def @@menu_char_end end |
#receive_input ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gem_menu.rb', line 100 def receive_input selection = nil while !self..include?(selection) selection = gets.strip.downcase if !self..include?(selection) puts "Invalid selection" end end launch_selection(selection) end |
#retreive_selection ⇒ Object
81 82 83 84 85 86 |
# File 'lib/gem_menu.rb', line 81 def retreive_selection puts "\n" puts "Please make your selection:".colorize(:light_green) receive_input end |
#retrieve_selection ⇒ Object
88 89 90 |
# File 'lib/gem_menu.rb', line 88 def retrieve_selection retreive_selection end |