Class: MenuCommander::Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (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(menu = nil)
  menu ||= config['menu']
  response = select menu
  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