Class: Laze::Section
- Includes:
- Enumerable
- Defined in:
- lib/laze/section.rb
Overview
A section is a special kind of Item that maps to a filesystem directory. You can move it around like an item, but it is actually a container object for its subitems.
A Section’s subitems can be accessed as an Enumerable.
Instance Attribute Summary
Attributes inherited from Item
#content, #parent, #properties
Instance Method Summary collapse
-
#add_item(item) ⇒ Object
(also: #<<)
Add a new subitem to this section.
- #each ⇒ Object
-
#initialize(properties) ⇒ Section
constructor
:nodoc:.
-
#number_of_subitems ⇒ Object
Count the number of subitems (and their subitems).
-
#remove_item(item) ⇒ Object
(also: #delete)
Remove the given subitem from this section.
Methods inherited from Item
#ancestors, #filename, #has?, #inspect, #to_s
Constructor Details
#initialize(properties) ⇒ Section
:nodoc:
10 11 12 13 |
# File 'lib/laze/section.rb', line 10 def initialize(properties) #:nodoc: super(properties, nil) @items = [] end |
Instance Method Details
#add_item(item) ⇒ Object Also known as: <<
Add a new subitem to this section.
20 21 22 23 |
# File 'lib/laze/section.rb', line 20 def add_item(item) @items << item item.parent = self end |
#each ⇒ Object
15 16 17 |
# File 'lib/laze/section.rb', line 15 def each @items.each { |item| yield item } end |
#number_of_subitems ⇒ Object
Count the number of subitems (and their subitems)
35 36 37 |
# File 'lib/laze/section.rb', line 35 def number_of_subitems @items.inject(0) { |total, item| total += 1 + item.number_of_subitems } end |
#remove_item(item) ⇒ Object Also known as: delete
Remove the given subitem from this section.
27 28 29 30 31 |
# File 'lib/laze/section.rb', line 27 def remove_item(item) @items.delete(item) item.parent = nil self end |