Class: Colloquy::Menu
- Inherits:
-
Object
- Object
- Colloquy::Menu
- Includes:
- Paginator
- Defined in:
- lib/colloquy/menu.rb
Instance Attribute Summary collapse
-
#flow ⇒ Object
Returns the value of attribute flow.
-
#keys ⇒ Object
Returns the value of attribute keys.
Instance Method Summary collapse
- #<<(symbol) ⇒ Object
- #[](symbol) ⇒ Object
- #empty? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize(options = {}) ⇒ Menu
constructor
A new instance of Menu.
- #key(input, page = @page) ⇒ Object
- #prefix(&block) ⇒ Object
- #prefix=(string) ⇒ Object
- #push(*args) ⇒ Object
- #render(page = @page) ⇒ Object
- #reset! ⇒ Object
- #suffix(&block) ⇒ Object
- #suffix=(string) ⇒ Object
Methods included from Paginator
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( = {}) @flow = [:flow] || nil @page = [:page] || 1 @prefix = [:prefix] @suffix = [:suffix] @keys = [] end |
Instance Attribute Details
#flow ⇒ Object
Returns the value of attribute flow.
5 6 7 |
# File 'lib/colloquy/menu.rb', line 5 def flow @flow end |
#keys ⇒ Object
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
52 53 54 |
# File 'lib/colloquy/menu.rb', line 52 def empty? @keys.empty? end |
#freeze ⇒ Object
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 |