Class: Ginbin::Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items: ItemsFromConfig.new, title: "Root") ⇒ Menu

Returns a new instance of Menu.



10
11
12
13
# File 'lib/ginbin/menu.rb', line 10

def initialize(items: ItemsFromConfig.new, title: "Root")
  @items = items
  @title = title
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/ginbin/menu.rb', line 8

def title
  @title
end

Instance Method Details

#callObject



15
16
17
18
19
# File 'lib/ginbin/menu.rb', line 15

def call
  prompt = TTY::Prompt.new

  prompt.enum_select("Choose command", choices).call
end

#choicesObject



21
22
23
24
25
# File 'lib/ginbin/menu.rb', line 21

def choices
  Items.new(@items).map do |command|
    { name: command.title, value: command }
  end
end