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
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.
- #limit ⇒ Object
- #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.
30 31 32 33 34 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 30 def initialize(page:, per:) @page = page @per = per freeze end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
10 11 12 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 10 def page @page end |
#per ⇒ Object (readonly)
Returns the value of attribute per.
10 11 12 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 10 def per @per end |
Class Method Details
.call(params) ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 12 def self.call(params) params = Params.with_indifferent_access(params) new( page: integer_param(params, :page, default: MIN_PAGE, min: MIN_PAGE), per: integer_param(params, :per, default: DEFAULT_PER, min: 1, max: MAX_PER) ) end |
Instance Method Details
#limit ⇒ Object
36 37 38 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 36 def limit per end |
#next_page?(total_count) ⇒ Boolean
48 49 50 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 48 def next_page?(total_count) offset + per < total_count.to_i end |
#offset ⇒ Object
40 41 42 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 40 def offset (page - 1) * per end |
#prev_page? ⇒ Boolean
44 45 46 |
# File 'app/services/llm_cost_tracker/dashboard/pagination.rb', line 44 def prev_page? page > MIN_PAGE end |