Class: MenuCommander::Menu
- Inherits:
-
Object
- Object
- MenuCommander::Menu
- Defined in:
- lib/menu_commander/menu.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(menu = nil) ⇒ Object
-
#initialize(config) ⇒ Menu
constructor
A new instance of Menu.
Constructor Details
#initialize(config) ⇒ Menu
Returns a new instance of Menu.
8 9 10 11 |
# File 'lib/menu_commander/menu.rb', line 8 def initialize(config) config = YAML.load_file config if config.is_a? String @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/menu_commander/menu.rb', line 6 def config @config end |
Instance Method Details
#call(menu = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/menu_commander/menu.rb', line 13 def call( = nil) ||= config['menu'] response = select response = response.join ' && ' if response.is_a? Array if response.is_a? String params = {} placeholders(response).each do |key| params[key.to_sym] = get_user_response key end response % params else call response end end |