Class: Colloquy::Menu

Inherits:
Object
  • Object
show all
Includes:
Paginator
Defined in:
lib/colloquy/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Paginator

included

Constructor Details

#initialize(options = {}) ⇒ Menu

Returns a new instance of Menu.



7
8
9
10
11
12
13
# File 'lib/colloquy/menu.rb', line 7

def initialize(options = {})
  @flow = options[:flow] || nil
  @page = options[:page] || 1
  @prefix = options[:prefix]
  @suffix = options[:suffix]
  @keys = []
end

Instance Attribute Details

#flowObject

Returns the value of attribute flow.



5
6
7
# File 'lib/colloquy/menu.rb', line 5

def flow
  @flow
end

#keysObject

Returns the value of attribute keys.



5
6
7
# File 'lib/colloquy/menu.rb', line 5

def keys
  @keys
end

Instance Method Details

#<<(symbol) ⇒ Object



46
47
48
49
50
# File 'lib/colloquy/menu.rb', line 46

def <<(symbol)
  @keys << symbol
  
  self
end

#[](symbol) ⇒ Object



56
57
58
# File 'lib/colloquy/menu.rb', line 56

def [](symbol)
  @keys[symbol]
end

#empty?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/colloquy/menu.rb', line 52

def empty?
  @keys.empty?
end

#freezeObject



60
61
62
# File 'lib/colloquy/menu.rb', line 60

def freeze
  @keys.freeze
end

#key(input, page = @page) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/colloquy/menu.rb', line 25

def key(input, page = @page)
  state = @flow.send(:state)
  
  return false unless input.to_i.to_s == input
  return false if input.to_i > @pages[page - 1].size
  
  key = if @pages
    @pages[page - 1][input.to_i - 1]
  end
  
  if key.respond_to? :push
    key.first
  else
    key
  end
end

#prefix(&block) ⇒ Object



64
65
66
# File 'lib/colloquy/menu.rb', line 64

def prefix(&block)
  @prefix_block = block
end

#prefix=(string) ⇒ Object



72
73
74
# File 'lib/colloquy/menu.rb', line 72

def prefix=(string)
  @prefix = string
end

#push(*args) ⇒ Object



42
43
44
# File 'lib/colloquy/menu.rb', line 42

def push(*args)
  @keys.push(*args)
end

#render(page = @page) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/colloquy/menu.rb', line 15

def render(page = @page)    
  paginate unless @pages
  
  assemble_prefix
  assemble_suffix
  
  execute_before_page_hook
  "#{render_prefix}#{render_body(page)}#{render_suffix}"
end

#reset!Object



80
81
82
83
84
85
86
# File 'lib/colloquy/menu.rb', line 80

def reset!
  @keys = []
  @pages = nil
  @page = 1
  @prefix = nil
  @suffix = nil
end

#suffix(&block) ⇒ Object



68
69
70
# File 'lib/colloquy/menu.rb', line 68

def suffix(&block)
  @suffix_block = block
end

#suffix=(string) ⇒ Object



76
77
78
# File 'lib/colloquy/menu.rb', line 76

def suffix=(string)
  @suffix = string
end