Class: Zwite::Pagination::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/zwite/core/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects, per_page) ⇒ Paginator

Initialization



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/zwite/core/pagination.rb', line 79

def initialize(objects, per_page)
  self.objects = objects
  self.per_page = per_page
  
  self.pages = []
  unless objects.count == 0
    self.pages_count = (self.objects.count / self.per_page.to_f).ceil
    self.pages_count.times do |i|
      page_start = self.per_page * i
      page_objects = self.objects[page_start..page_start + self.per_page - 1]
      page = Page.new(self, page_objects, i + 1)
      self.pages << page
    end
  end
  
end

Instance Attribute Details

#objectsObject

Properties



62
63
64
# File 'lib/zwite/core/pagination.rb', line 62

def objects
  @objects
end

#pagesObject

Returns the value of attribute pages.



64
65
66
# File 'lib/zwite/core/pagination.rb', line 64

def pages
  @pages
end

#pages_countObject

Returns the value of attribute pages_count.



65
66
67
# File 'lib/zwite/core/pagination.rb', line 65

def pages_count
  @pages_count
end

#per_pageObject

Returns the value of attribute per_page.



63
64
65
# File 'lib/zwite/core/pagination.rb', line 63

def per_page
  @per_page
end

Instance Method Details

#to_liquidObject



67
68
69
70
71
72
73
74
# File 'lib/zwite/core/pagination.rb', line 67

def to_liquid
  return {
    "objects" => self.objects,
    "per_page" => self.per_page,
    "pages" => self.pages,
    "pages_count" => self.pages_count
  }
end