Class: Gumdrop::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/gumdrop/data_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(articles, base_path = "/page", page_size = 5) ⇒ Pager

Returns a new instance of Pager.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/gumdrop/data_manager.rb', line 165

def initialize(articles, base_path="/page", page_size=5)
  @all= articles
  @page_size= page_size
  @base_path= base_path
  @page_sets= @all.in_groups_of(page_size, false)
  @pages= []
  @current_page=1
  @page_sets.each do |art_ary|
    @pages << HashObject.new({
      items: art_ary,
      page: @current_page,
      uri: "#{base_path}/#{current_page}",
      pager: self
    })
    @current_page += 1
  end
  @current_page= nil
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



163
164
165
# File 'lib/gumdrop/data_manager.rb', line 163

def all
  @all
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



163
164
165
# File 'lib/gumdrop/data_manager.rb', line 163

def base_url
  @base_url
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



163
164
165
# File 'lib/gumdrop/data_manager.rb', line 163

def current_page
  @current_page
end

#page_setsObject (readonly)

Returns the value of attribute page_sets.



163
164
165
# File 'lib/gumdrop/data_manager.rb', line 163

def page_sets
  @page_sets
end

#pagesObject (readonly)

Returns the value of attribute pages.



163
164
165
# File 'lib/gumdrop/data_manager.rb', line 163

def pages
  @pages
end

Instance Method Details

#[](key) ⇒ Object



205
206
207
# File 'lib/gumdrop/data_manager.rb', line 205

def [](key)
  @pages[key]
end

#eachObject



196
197
198
199
200
201
202
203
# File 'lib/gumdrop/data_manager.rb', line 196

def each
  @current_page=1
  @pages.each do |page_set|
    yield page_set
    @current_page += 1
  end
  @current_page= nil
end

#firstObject



188
189
190
# File 'lib/gumdrop/data_manager.rb', line 188

def first
  @pages.first
end

#lastObject



192
193
194
# File 'lib/gumdrop/data_manager.rb', line 192

def last
  @pages.last
end

#lengthObject



184
185
186
# File 'lib/gumdrop/data_manager.rb', line 184

def length
  @pages.length
end