Class: Waiter::Menu::ItemList
- Inherits:
-
Array
- Object
- Array
- Waiter::Menu::ItemList
- Defined in:
- lib/waiter/menu/item_list.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #include?(other) ⇒ Boolean
-
#initialize(ary = [], sort_options = {}) ⇒ ItemList
constructor
A new instance of ItemList.
- #names ⇒ Object
- #sort(options = {}) ⇒ Object
Constructor Details
#initialize(ary = [], sort_options = {}) ⇒ ItemList
Returns a new instance of ItemList.
4 5 6 7 |
# File 'lib/waiter/menu/item_list.rb', line 4 def initialize(ary = [], = {}) super(ary) sort() end |
Instance Method Details
#[](index) ⇒ Object
14 15 16 17 |
# File 'lib/waiter/menu/item_list.rb', line 14 def [](index) return detect{ |item| item.name == index } if index.is_a? Symbol super end |
#include?(other) ⇒ Boolean
9 10 11 12 |
# File 'lib/waiter/menu/item_list.rb', line 9 def include?(other) return map(&:name).include?(other) if other.is_a? Symbol super end |
#names ⇒ Object
19 20 21 |
# File 'lib/waiter/menu/item_list.rb', line 19 def names map(&:name) end |
#sort(options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/waiter/menu/item_list.rb', line 23 def sort( = {}) sort_by!(&[:sort].to_sym) if .fetch(:sort, false) reverse! if .fetch(:reverse, false) end |