Class: PageListFormatStrategies::WithUniqueViewCount

Inherits:
Base
  • Object
show all
Defined in:
lib/page_list_format_strategies/with_unique_view_count.rb

Overview

A presentation strategy that presents a list of pages in descending order by the number of unique views with its unique view count.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PageListFormatStrategies::Base

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/page_list_format_strategies/with_unique_view_count.rb', line 9

def call
  presentation_strategy = proc do |page|
    str = ''
    str += "#{page.path} #{page.unique_view_count} "
    str += "unique visit#{page.unique_view_count > 1 ? 's' : ''}"
    str
  end

  pages.sort_by { |page| -page.unique_view_count }
       .map { |page| page.to_s(strategy: presentation_strategy) }
end