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.
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
#all ⇒ Object (readonly)
Returns the value of attribute all.
163 164 165 |
# File 'lib/gumdrop/data_manager.rb', line 163 def all @all end |
#base_url ⇒ Object (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_page ⇒ Object (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_sets ⇒ Object (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 |
#pages ⇒ Object (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 |
#each ⇒ Object
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 |
#first ⇒ Object
188 189 190 |
# File 'lib/gumdrop/data_manager.rb', line 188 def first @pages.first end |
#last ⇒ Object
192 193 194 |
# File 'lib/gumdrop/data_manager.rb', line 192 def last @pages.last end |
#length ⇒ Object
184 185 186 |
# File 'lib/gumdrop/data_manager.rb', line 184 def length @pages.length end |