Class: PageIterator
- Inherits:
-
Object
- Object
- PageIterator
- Defined in:
- lib/page_iterator.rb
Constant Summary collapse
- DEFAULT_ITENS_PER_PAGE =
50
Instance Attribute Summary collapse
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_itens ⇒ Object
readonly
Returns the value of attribute total_itens.
Instance Method Summary collapse
- #each_remaining_page! ⇒ Object
-
#initialize(total_itens, logfile, itens_per_page = DEFAULT_ITENS_PER_PAGE) ⇒ PageIterator
constructor
A new instance of PageIterator.
- #next! ⇒ Object
- #previous! ⇒ Object
- #remaining_itens ⇒ Object
- #remaining_pages ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(total_itens, logfile, itens_per_page = DEFAULT_ITENS_PER_PAGE) ⇒ PageIterator
Returns a new instance of PageIterator.
6 7 8 9 10 11 |
# File 'lib/page_iterator.rb', line 6 def initialize(total_itens, logfile, itens_per_page=DEFAULT_ITENS_PER_PAGE) @total_itens = total_itens @itens_per_page = itens_per_page @logfile = logfile @current_page = current_page_from_file end |
Instance Attribute Details
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
4 5 6 |
# File 'lib/page_iterator.rb', line 4 def per_page @per_page end |
#total_itens ⇒ Object (readonly)
Returns the value of attribute total_itens.
4 5 6 |
# File 'lib/page_iterator.rb', line 4 def total_itens @total_itens end |
Instance Method Details
#each_remaining_page! ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/page_iterator.rb', line 45 def each_remaining_page! remaining_pages.each do |page| yield page self.next! end self.next! end |
#next! ⇒ Object
23 24 25 26 |
# File 'lib/page_iterator.rb', line 23 def next! @current_page += 1 log @current_page end |
#previous! ⇒ Object
28 29 30 31 |
# File 'lib/page_iterator.rb', line 28 def previous! @current_page -= 1 log @current_page end |
#remaining_itens ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/page_iterator.rb', line 33 def remaining_itens if @current_page > total_pages 0 else @total_itens - (@current_page - 1) * @itens_per_page end end |
#remaining_pages ⇒ Object
41 42 43 |
# File 'lib/page_iterator.rb', line 41 def remaining_pages @current_page..total_pages end |
#total_pages ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/page_iterator.rb', line 13 def total_pages pages = @total_itens / @itens_per_page if pages == 0 1 else last_page_itens = @total_itens % @itens_per_page last_page_itens > 0 ? pages + 1 : pages end end |