Class: Wor::Paginate::Formatter

Inherits:
Object
  • Object
show all
Includes:
Utils::UriHelper
Defined in:
lib/wor/paginate/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::UriHelper

query_params, replace_query_params

Constructor Details

#initialize(adapter, options = {}) ⇒ Formatter

Returns a new instance of Formatter.



9
10
11
12
# File 'lib/wor/paginate/formatter.rb', line 9

def initialize(adapter, options = {})
  @adapter = adapter
  @options = options
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



7
8
9
# File 'lib/wor/paginate/formatter.rb', line 7

def adapter
  @adapter
end

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/wor/paginate/formatter.rb', line 7

def content
  @content
end

#formatterObject

Returns the value of attribute formatter.



7
8
9
# File 'lib/wor/paginate/formatter.rb', line 7

def formatter
  @formatter
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/wor/paginate/formatter.rb', line 7

def options
  @options
end

Instance Method Details

#formatObject

rubocop: disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wor/paginate/formatter.rb', line 14

def format # rubocop: disable Metrics/MethodLength
  {
    page: serialized_content,
    count: count,
    total_pages: total_pages,
    total_count: options[:total_count] || total_count,
    current_page: current_page,
    previous_page: previous_page,
    next_page: next_page,
    next_page_url: page_url(next_page),
    previous_page_url: page_url(previous_page)
  }
end