Class: Gumdrop::Util::Pager
- Inherits:
-
Object
- Object
- Gumdrop::Util::Pager
- Defined in:
- lib/gumdrop/util/pager.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#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
- #current ⇒ Object
- #each ⇒ Object
- #each_with_index ⇒ 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.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gumdrop/util/pager.rb', line 6 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.from({ 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.
4 5 6 |
# File 'lib/gumdrop/util/pager.rb', line 4 def all @all end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
4 5 6 |
# File 'lib/gumdrop/util/pager.rb', line 4 def base_path @base_path end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
4 5 6 |
# File 'lib/gumdrop/util/pager.rb', line 4 def current_page @current_page end |
#page_sets ⇒ Object (readonly)
Returns the value of attribute page_sets.
4 5 6 |
# File 'lib/gumdrop/util/pager.rb', line 4 def page_sets @page_sets end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
4 5 6 |
# File 'lib/gumdrop/util/pager.rb', line 4 def pages @pages end |
Instance Method Details
#[](key) ⇒ Object
59 60 61 |
# File 'lib/gumdrop/util/pager.rb', line 59 def [](key) @pages[key] end |
#current ⇒ Object
25 26 27 |
# File 'lib/gumdrop/util/pager.rb', line 25 def current @pages.fetch(@current_page, nil) end |
#each ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/gumdrop/util/pager.rb', line 41 def each @current_page=1 @pages.each do |page_set| yield page_set @current_page += 1 end @current_page= nil end |
#each_with_index ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/gumdrop/util/pager.rb', line 50 def each_with_index @current_page=1 @pages.each do |page_set| yield page_set, @current_page - 1 @current_page += 1 end @current_page= nil end |
#first ⇒ Object
33 34 35 |
# File 'lib/gumdrop/util/pager.rb', line 33 def first @pages.first end |
#last ⇒ Object
37 38 39 |
# File 'lib/gumdrop/util/pager.rb', line 37 def last @pages.last end |
#length ⇒ Object
29 30 31 |
# File 'lib/gumdrop/util/pager.rb', line 29 def length @pages.length end |