Class: SwedbankPay::SidebarPageCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/sidebar_page_collection.rb

Overview

Arranges Sidebar pages into a tree

Instance Method Summary collapse

Constructor Details

#initialize(parent, pages = []) ⇒ SidebarPageCollection

Returns a new instance of SidebarPageCollection.

Raises:

  • (ArgumentError)


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

#countObject



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_liquidObject



36
37
38
# File 'lib/sidebar_page_collection.rb', line 36

def to_liquid
  @pages
end