Class: SwedbankPay::SidebarPageCollection
- Inherits:
-
Object
- Object
- SwedbankPay::SidebarPageCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/sidebar_page_collection.rb
Overview
Arranges Sidebar pages into a tree
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(parent, pages = []) ⇒ SidebarPageCollection
constructor
A new instance of SidebarPageCollection.
- #to_liquid ⇒ Object
Constructor Details
#initialize(parent, pages = []) ⇒ SidebarPageCollection
Returns a new instance of SidebarPageCollection.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sidebar_page_collection.rb', line 12 def initialize(parent, pages = []) raise ArgumentError, 'Pages must be an array' unless pages.is_a? Array @pages = [] pages.each_with_index do |page, index| page.number = index page.parent = parent @pages.push(page) end end |
Instance Method Details
#count ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sidebar_page_collection.rb', line 24 def count return 0 if @pages.empty? count = @pages.length @pages.each do |page| count += page.children.count end count end |
#to_liquid ⇒ Object
36 37 38 |
# File 'lib/sidebar_page_collection.rb', line 36 def to_liquid @pages end |