Class: Sortable
- Inherits:
-
Object
- Object
- Sortable
- Defined in:
- lib/sort_n_params/sortable.rb
Constant Summary collapse
- DEFAULT_ORDER =
'asc'.freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(column, title, params) ⇒ Sortable
constructor
A new instance of Sortable.
Constructor Details
#initialize(column, title, params) ⇒ Sortable
Returns a new instance of Sortable.
7 8 9 10 11 12 |
# File 'lib/sort_n_params/sortable.rb', line 7 def initialize(column, title, params) @column = column @title = title || column.titleize @params = params @sort_params = { order: [], filter: @params[:filter] } end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sort_n_params/sortable.rb', line 14 def call add_previous_order unless @params[:order].nil? if @sort_params[:order].include?(@column) revert_order set_clear_params set_position else add_order reset_clear_params end build_data end |