Class: LlmCostTracker::Dashboard::Pagination
- Inherits:
-
Object
- Object
- LlmCostTracker::Dashboard::Pagination
- Defined in:
- app/services/llm_cost_tracker/dashboard/pagination.rb
Constant Summary collapse
- DEFAULT_PER =
50- MAX_PER =
200- MIN_PAGE =
1- MIN_PER =
1
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per ⇒ Object
readonly
Returns the value of attribute per.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(page:, per:) ⇒ Pagination
constructor
A new instance of Pagination.
- #next_page?(total_count) ⇒ Boolean
- #offset ⇒ Object
- #prev_page? ⇒ Boolean
- #total_pages(total_count) ⇒ Object
Constructor Details
#initialize(page:, per:) ⇒ Pagination
Returns a new instance of Pagination.
31 32 33 34 35 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 31 def initialize(page:, per:) @page = page @per = per freeze end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
11 12 13 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 11 def page @page end |
#per ⇒ Object (readonly)
Returns the value of attribute per.
11 12 13 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 11 def per @per end |
Class Method Details
.call(params) ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 13 def self.call(params) params = Params.to_hash(params).symbolize_keys new( page: integer_param(params, :page, default: MIN_PAGE, min: MIN_PAGE), per: integer_param(params, :per, default: DEFAULT_PER, min: MIN_PER, max: MAX_PER) ) end |
Instance Method Details
#next_page?(total_count) ⇒ Boolean
45 46 47 48 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 45 def next_page?(total_count) total_count = total_count.to_i offset + per < total_count end |
#offset ⇒ Object
37 38 39 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 37 def offset (page - 1) * per end |
#prev_page? ⇒ Boolean
41 42 43 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 41 def prev_page? page > MIN_PAGE end |
#total_pages(total_count) ⇒ Object
50 51 52 53 54 55 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 50 def total_pages(total_count) total_count = total_count.to_i return MIN_PAGE unless total_count.positive? ((total_count + per - 1) / per) end |