Class: WillSortate::SorterHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/will_sortate/helpers/sorter_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ SorterHelper

Returns a new instance of SorterHelper.



3
4
5
6
7
8
# File 'lib/will_sortate/helpers/sorter_helper.rb', line 3

def initialize args
  @collection = args[:collection]
  @sort_field = args[:sort_field]
  @default_sort_order = args[:default_sort_order] || 'asc'
  @params = args[:params]
end

Instance Method Details

#next_sort_orderObject



10
11
12
13
14
15
16
# File 'lib/will_sortate/helpers/sorter_helper.rb', line 10

def next_sort_order
  if @collection.sortated_field == @sort_field.to_s
    @collection.sortated_order == 'asc' && 'desc' || 'asc'
  else
    @default_sort_order
  end
end

#paramsObject



18
19
20
# File 'lib/will_sortate/helpers/sorter_helper.rb', line 18

def params
  @params.merge sort: "#{@sort_field}_#{next_sort_order}"
end