Class: TMBundle::Menu::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/tm_bundle/item.rb

Direct Known Subclasses

Separator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid, order, name: nil, items: [], parent: nil) ⇒ Item

Returns a new instance of Item.



5
6
7
8
9
10
11
12
# File 'lib/tm_bundle/item.rb', line 5

def initialize(uuid, order, name: nil, items: [], parent: nil)
  @exclude = false
  self.uuid   = uuid
  self.name   = name
  self.items  = items
  self.parent = parent
  self.order  = order
end

Instance Attribute Details

#excludeObject

Returns the value of attribute exclude.



4
5
6
# File 'lib/tm_bundle/item.rb', line 4

def exclude
  @exclude
end

#itemsObject

Returns the value of attribute items.



4
5
6
# File 'lib/tm_bundle/item.rb', line 4

def items
  @items
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/tm_bundle/item.rb', line 4

def name
  @name
end

#orderObject

Returns the value of attribute order.



4
5
6
# File 'lib/tm_bundle/item.rb', line 4

def order
  @order
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/tm_bundle/item.rb', line 4

def parent
  @parent
end

#uuidObject

Returns the value of attribute uuid.



4
5
6
# File 'lib/tm_bundle/item.rb', line 4

def uuid
  @uuid
end

Instance Method Details

#checkout(options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/tm_bundle/item.rb', line 14

def checkout(options = {})
  self.name ||= options[:name]
  self.parent ||= options[:parent]
  self.order ||= options[:order]
  self.items = Array.wrap(options[:items])
  self
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/tm_bundle/item.rb', line 30

def eql?(other)
  uuid == other.uuid
end

#inspectObject



34
35
36
# File 'lib/tm_bundle/item.rb', line 34

def inspect
  "#{order||:nil}> * #{name || uuid}"
end

#name?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/tm_bundle/item.rb', line 38

def name?
  name.present?
end

#process_items(uuids) ⇒ Object



26
27
28
# File 'lib/tm_bundle/item.rb', line 26

def process_items(uuids)
  uuids.map.with_index{|id, index| Menu.find_or_create_new_item(id, index, parent: uuid) }
end

#root?Boolean

Returns:

  • (Boolean)


44
# File 'lib/tm_bundle/item.rb', line 44

def root?; !@parent; end

#separator?Boolean

Returns:

  • (Boolean)


45
# File 'lib/tm_bundle/item.rb', line 45

def separator?; false; end

#to_sObject



43
# File 'lib/tm_bundle/item.rb', line 43

def to_s; name; end