Class: Gumdrop::Pager
- Inherits:
-
Object
- Object
- Gumdrop::Pager
- Defined in:
- lib/gumdrop/data_manager.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#page_sets ⇒ Object
readonly
Returns the value of attribute page_sets.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(articles, base_path = "/page", page_size = 5) ⇒ Pager
constructor
A new instance of Pager.
- #last ⇒ Object
- #length ⇒ Object
Constructor Details
#initialize(articles, base_path = "/page", page_size = 5) ⇒ Pager
Returns a new instance of Pager.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/gumdrop/data_manager.rb', line 169 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
#all ⇒ Object (readonly)
Returns the value of attribute all.
167 168 169 |
# File 'lib/gumdrop/data_manager.rb', line 167 def all @all end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
167 168 169 |
# File 'lib/gumdrop/data_manager.rb', line 167 def base_url @base_url end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
167 168 169 |
# File 'lib/gumdrop/data_manager.rb', line 167 def current_page @current_page end |
#page_sets ⇒ Object (readonly)
Returns the value of attribute page_sets.
167 168 169 |
# File 'lib/gumdrop/data_manager.rb', line 167 def page_sets @page_sets end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
167 168 169 |
# File 'lib/gumdrop/data_manager.rb', line 167 def pages @pages end |
Instance Method Details
#[](key) ⇒ Object
209 210 211 |
# File 'lib/gumdrop/data_manager.rb', line 209 def [](key) @pages[key] end |
#each ⇒ Object
200 201 202 203 204 205 206 207 |
# File 'lib/gumdrop/data_manager.rb', line 200 def each @current_page=1 @pages.each do |page_set| yield page_set @current_page += 1 end @current_page= nil end |
#first ⇒ Object
192 193 194 |
# File 'lib/gumdrop/data_manager.rb', line 192 def first @pages.first end |
#last ⇒ Object
196 197 198 |
# File 'lib/gumdrop/data_manager.rb', line 196 def last @pages.last end |
#length ⇒ Object
188 189 190 |
# File 'lib/gumdrop/data_manager.rb', line 188 def length @pages.length end |