Class: RsPaginator::PageInfo

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper
Defined in:
lib/rs_paginator/page_info.rb

Instance Method Summary collapse

Constructor Details

#initialize(objects, context) ⇒ PageInfo

Returns a new instance of PageInfo.



8
9
10
11
# File 'lib/rs_paginator/page_info.rb', line 8

def initialize(objects, context)
  @objects = objects
  @context = context
end

Instance Method Details

#renderObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rs_paginator/page_info.rb', line 13

def render
  (:div, class: 'page_info') do
    if @objects.empty?
      @context.t('rs_paginator.page_info.empty')
    elsif @objects.total_pages == 1 && @objects.count == 1
      @context.t('rs_paginator.page_info.one')
    elsif @objects.total_pages == 1
      @context.t('rs_paginator.page_info.one_page', total: @objects.total)
    else
      from = @objects.per_page * (@objects.page - 1) + 1
      to = from + @objects.count - 1
      @context.t('rs_paginator.page_info.other', from: from, to: to, total: @objects.total)
    end
  end
end