Class: SlackBot::Pager
- Inherits:
-
Object
- Object
- SlackBot::Pager
- Defined in:
- lib/slack_bot/pager.rb
Constant Summary collapse
- DEFAULT_PAGE =
1
- DEFAULT_LIMIT =
10
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#source_cursor ⇒ Object
readonly
Returns the value of attribute source_cursor.
Instance Method Summary collapse
- #cursor ⇒ Object
-
#initialize(source_cursor, args:, limit: nil, page: nil) ⇒ Pager
constructor
A new instance of Pager.
- #offset ⇒ Object
- #pages_count ⇒ Object
- #total_count ⇒ Object
Constructor Details
#initialize(source_cursor, args:, limit: nil, page: nil) ⇒ Pager
Returns a new instance of Pager.
7 8 9 10 11 12 |
# File 'lib/slack_bot/pager.rb', line 7 def initialize(source_cursor, args:, limit: nil, page: nil) @source_cursor = source_cursor @args = args @limit = limit || @args[:per_page]&.to_i || DEFAULT_LIMIT @page = page || @args[:page]&.to_i || DEFAULT_PAGE end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/slack_bot/pager.rb', line 6 def args @args end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
6 7 8 |
# File 'lib/slack_bot/pager.rb', line 6 def limit @limit end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'lib/slack_bot/pager.rb', line 6 def page @page end |
#source_cursor ⇒ Object (readonly)
Returns the value of attribute source_cursor.
6 7 8 |
# File 'lib/slack_bot/pager.rb', line 6 def source_cursor @source_cursor end |
Instance Method Details
#cursor ⇒ Object
26 27 28 |
# File 'lib/slack_bot/pager.rb', line 26 def cursor source_cursor.limit(limit).offset(offset) end |
#offset ⇒ Object
22 23 24 |
# File 'lib/slack_bot/pager.rb', line 22 def offset (page - 1) * limit end |
#pages_count ⇒ Object
18 19 20 |
# File 'lib/slack_bot/pager.rb', line 18 def pages_count (source_cursor.count.to_f / limit).ceil end |
#total_count ⇒ Object
14 15 16 |
# File 'lib/slack_bot/pager.rb', line 14 def total_count source_cursor.count end |