Class: OrangeZest::Group

Inherits:
Component show all
Defined in:
lib/orange_zest/group.rb

Overview

Wraps a collection of ‘Component`s into a single `Component`.

The associated instance within this class, ‘Main`, is a special group available everywhere which components can be added to easily.

Constant Summary collapse

Main =
new

Instance Attribute Summary collapse

Attributes inherited from Component

#group

Instance Method Summary collapse

Methods inherited from Component

anon, #register, #unregister

Constructor Details

#initializeGroup

Returns a new instance of Group.



13
14
15
16
# File 'lib/orange_zest/group.rb', line 13

def initialize
  @items = []
  @enabled = true
end

Instance Attribute Details

#enabledBoolean Also known as: enabled?

Whether to call ‘#update` or `#draw` on the items in this group.

Returns:

  • (Boolean)


20
21
22
# File 'lib/orange_zest/group.rb', line 20

def enabled
  @enabled
end

#items<Component>

The items within this group.

Returns:



11
12
13
# File 'lib/orange_zest/group.rb', line 11

def items
  @items
end

Instance Method Details

#add(component) ⇒ Object Also known as: <<

Adds a component to this group.

Parameters:



25
26
27
# File 'lib/orange_zest/group.rb', line 25

def add(component)
  @items << component
end

#drawObject



42
43
44
45
# File 'lib/orange_zest/group.rb', line 42

def draw
  return unless enabled?
  items.each(&:draw)
end

#remove(component) ⇒ Object Also known as: delete

Removes a component from this group.

Parameters:



32
33
34
# File 'lib/orange_zest/group.rb', line 32

def remove(component)
  @items.delete(component)
end

#updateObject



37
38
39
40
# File 'lib/orange_zest/group.rb', line 37

def update
  return unless enabled?
  items.each(&:update)
end