Class: ImHungry::Paginate
- Inherits:
-
Object
- Object
- ImHungry::Paginate
- Defined in:
- lib/im_hungry/paginate.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
Instance Method Summary collapse
-
#initialize(array, per_page) ⇒ Paginate
constructor
A new instance of Paginate.
- #page_lines(page, i) ⇒ Object
- #pages ⇒ Object
- #print ⇒ Object
- #print_page(page, i) ⇒ Object
Constructor Details
#initialize(array, per_page) ⇒ Paginate
Returns a new instance of Paginate.
5 6 7 8 |
# File 'lib/im_hungry/paginate.rb', line 5 def initialize(array, per_page) self.array = array self.per_page = per_page end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
3 4 5 |
# File 'lib/im_hungry/paginate.rb', line 3 def array @array end |
#per_page ⇒ Object
Returns the value of attribute per_page.
3 4 5 |
# File 'lib/im_hungry/paginate.rb', line 3 def per_page @per_page end |
Instance Method Details
#page_lines(page, i) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/im_hungry/paginate.rb', line 14 def page_lines(page, i) [ '', "Page #{i + 1} of #{pages.length}", page.map(&:to_s) ] end |
#pages ⇒ Object
10 11 12 |
# File 'lib/im_hungry/paginate.rb', line 10 def pages @pages ||= array.each_slice(per_page).to_a end |
#print ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/im_hungry/paginate.rb', line 26 def print puts puts 'Here is what is open:' pages.each_with_index do |page, i| print_page(page, i) last_page = i == pages.length - 1 Readline.readline('Next page?', true) unless last_page end end |
#print_page(page, i) ⇒ Object
22 23 24 |
# File 'lib/im_hungry/paginate.rb', line 22 def print_page(page, i) puts page_lines(page, i) end |