Class: Jekyll_Tagger::Pager
- Inherits:
-
Object
- Object
- Jekyll_Tagger::Pager
- Defined in:
- lib/jekyll_tagger/pager.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
writeonly
Sets the attribute index.
-
#item_count ⇒ Object
readonly
Returns the value of attribute item_count.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#url_maker ⇒ Object
readonly
Returns the value of attribute url_maker.
Instance Method Summary collapse
-
#initialize(items, page_size, url_maker) ⇒ Pager
constructor
A new instance of Pager.
- #page_first(number) ⇒ Object
- #page_items(kk) ⇒ Object
- #page_last(number) ⇒ Object
- #page_list(number, page_show, current) ⇒ Object
- #page_next(number) ⇒ Object
- #page_prev(number) ⇒ Object
Constructor Details
#initialize(items, page_size, url_maker) ⇒ Pager
Returns a new instance of Pager.
5 6 7 8 9 10 11 12 |
# File 'lib/jekyll_tagger/pager.rb', line 5 def initialize(items,page_size,url_maker) @items = items @page_size = page_size @url_maker = url_maker @item_count = items.count @page_count = @page_size != 0 ? ((@item_count / @page_size) + (@item_count % @page_size > 0 ? 1 : 0)) : 1 end |
Instance Attribute Details
#index=(value) ⇒ Object (writeonly)
Sets the attribute index
4 5 6 |
# File 'lib/jekyll_tagger/pager.rb', line 4 def index=(value) @index = value end |
#item_count ⇒ Object (readonly)
Returns the value of attribute item_count.
3 4 5 |
# File 'lib/jekyll_tagger/pager.rb', line 3 def item_count @item_count end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/jekyll_tagger/pager.rb', line 3 def items @items end |
#page_count ⇒ Object (readonly)
Returns the value of attribute page_count.
3 4 5 |
# File 'lib/jekyll_tagger/pager.rb', line 3 def page_count @page_count end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
3 4 5 |
# File 'lib/jekyll_tagger/pager.rb', line 3 def page_size @page_size end |
#url_maker ⇒ Object (readonly)
Returns the value of attribute url_maker.
3 4 5 |
# File 'lib/jekyll_tagger/pager.rb', line 3 def url_maker @url_maker end |
Instance Method Details
#page_first(number) ⇒ Object
47 48 49 |
# File 'lib/jekyll_tagger/pager.rb', line 47 def page_first(number) return PageInfo.new(self,1,number==1) end |
#page_items(kk) ⇒ Object
14 15 16 |
# File 'lib/jekyll_tagger/pager.rb', line 14 def page_items(kk) return @page_size != 0 ? @items[((kk-1)*@page_size)..(kk*@page_size-1)] : @items end |
#page_last(number) ⇒ Object
50 51 52 |
# File 'lib/jekyll_tagger/pager.rb', line 50 def page_last(number) return PageInfo.new(self,@page_count,number==@page_count) end |
#page_list(number, page_show, current) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jekyll_tagger/pager.rb', line 18 def page_list(number,page_show,current) pages = [] ps = page_show-1 s1 = current - ps/2 s2 = current + ps/2 + ps%2 if s1 < 1 s2 += (1 - s1) s1 = 1 end if s2 > page_count s1 -= (s2 - page_count) s2 = page_count if s1 < 1 s1 = 1 end end for kk in (s1)..(s2) pages.push(PageInfo.new(self,kk,kk==current)) end return pages end |