Class: Waiter::Menu

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/waiter/menu.rb,
lib/waiter/menu/item.rb,
lib/waiter/menu/column.rb,
lib/waiter/menu/drawer.rb,
lib/waiter/menu/section.rb,
lib/waiter/menu/item_list.rb

Defined Under Namespace

Classes: Column, Drawer, Item, ItemList, Section

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

#column, #method_missing, #section

Constructor Details

#initialize(name, context, options = {}) ⇒ Menu

Returns a new instance of Menu.



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

def initialize(name, context, options = {})
  @name = name
  @context = context
  @items = ItemList.new
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Waiter::DSL

Instance Attribute Details

#contextObject

Returns the value of attribute context.



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

def context
  @context
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

Returns the value of attribute submenu.



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

def submenu
  @submenu
end

Class Method Details

.serve(name, context = nil, options = {}, &block) ⇒ Object



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

def self.serve(name, context = nil, options = {}, &block)
  new(name, context, options).tap do |menu|
    menu.update(&block)
  end
end

Instance Method Details

#[](name) ⇒ Object



54
55
56
# File 'lib/waiter/menu.rb', line 54

def [](name)
  items[name]
end

#add(name, path = {}, options = {}, &block) ⇒ Object



36
37
38
# File 'lib/waiter/menu.rb', line 36

def add(name, path = {}, options = {}, &block)
  items << Item.new(self, name, path, options, &block)
end

#add_column(options = {}, &block) ⇒ Object



45
46
47
48
# File 'lib/waiter/menu.rb', line 45

def add_column(options = {}, &block)
  column = Column.new(self, options, &block)
  items << column unless column.empty?
end

#add_section(options = {}, &block) ⇒ Object



40
41
42
43
# File 'lib/waiter/menu.rb', line 40

def add_section(options = {}, &block)
  section = Section.new(self, options, &block)
  items << section unless section.empty?
end

#draw(context = nil) ⇒ Object



32
33
34
# File 'lib/waiter/menu.rb', line 32

def draw(context = nil)
  Drawer.new(self, context).draw
end

#inspectObject



67
68
69
# File 'lib/waiter/menu.rb', line 67

def inspect
  "#<#{self.class.name}:#{'0x%x' % (36971870 << 1)} name=#{name.inspect} options=#{options.inspect}>"
end

#items(sorted = false) ⇒ Object



58
59
60
61
# File 'lib/waiter/menu.rb', line 58

def items(sorted = false)
  return @items unless sorted
  ItemList.new(@items, options.slice(:sort, :reverse))
end

#sectionsObject



50
51
52
# File 'lib/waiter/menu.rb', line 50

def sections
  items.select(&:section?) || []
end

#top?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/waiter/menu.rb', line 63

def top?
  parent.nil?
end

#update(&block) ⇒ Object



28
29
30
# File 'lib/waiter/menu.rb', line 28

def update(&block)
  instance_eval(&block)
end