Module: TelegramOnSteroids::Keyboard::Paginatable
- Defined in:
- lib/telegram_on_steroids/keyboard/paginatable.rb
Constant Summary collapse
- DEFAULT_PER_PAGE =
2
Instance Method Summary collapse
- #current_page ⇒ Object
- #first_page? ⇒ Boolean
- #last_page? ⇒ Boolean
- #navigation_buttons ⇒ Object
- #next_button ⇒ Object
- #offset ⇒ Object
- #paginatable ⇒ Object
- #per_page ⇒ Object
- #per_page=(val) ⇒ Object
- #prev_button ⇒ Object
- #to_telegram_format ⇒ Object
Instance Method Details
#current_page ⇒ Object
30 31 32 33 34 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 30 def current_page return action.session.read(:current_page) || 1 unless request.params.callback_data =~ /page/ request.params.callback_data.scan(/\d+/).first.to_i end |
#first_page? ⇒ Boolean
44 45 46 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 44 def first_page? current_page == 1 end |
#last_page? ⇒ Boolean
40 41 42 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 40 def last_page? current_page * per_page >= .size end |
#navigation_buttons ⇒ Object
15 16 17 18 19 20 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 15 def return [] if last_page? return [] if first_page? [, ] end |
#next_button ⇒ Object
52 53 54 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 52 def { text: 'Next >>', callback_data: "page_#{current_page + 1}" } end |
#offset ⇒ Object
36 37 38 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 36 def offset (current_page - 1) * per_page end |
#paginatable ⇒ Object
4 5 6 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 4 def paginatable true end |
#per_page ⇒ Object
22 23 24 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 22 def per_page @per_page || DEFAULT_PER_PAGE end |
#per_page=(val) ⇒ Object
26 27 28 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 26 def per_page=(val) @per_page = val end |
#prev_button ⇒ Object
48 49 50 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 48 def { text: '<< Prev', callback_data: "page_#{current_page - 1}" } end |
#to_telegram_format ⇒ Object
8 9 10 11 12 13 |
# File 'lib/telegram_on_steroids/keyboard/paginatable.rb', line 8 def to_telegram_format action.session.write(:current_page, current_page) return if first_page? && last_page? [offset...offset + per_page].push() end |