Class: SortySorter::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/sorty_sorter/params.rb

Constant Summary collapse

DEFAULT_SORT_KEY =
:updated_at
DEFAULT_SORT_DIR =
:desc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(col, dir, collection) ⇒ Params

TODO: Maybe set some default sort columns



10
11
12
13
14
15
# File 'lib/sorty_sorter/params.rb', line 10

def initialize(col, dir, collection)
  @column = :"#{col}"
  @direction = :"#{dir}"
  @collection = collection
  @defined_cols = collection.sort_columns
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/sorty_sorter/params.rb', line 3

def collection
  @collection
end

#columnObject (readonly)

Returns the value of attribute column.



3
4
5
# File 'lib/sorty_sorter/params.rb', line 3

def column
  @column
end

#defined_colsObject (readonly)

Returns the value of attribute defined_cols.



3
4
5
# File 'lib/sorty_sorter/params.rb', line 3

def defined_cols
  @defined_cols
end

#directionObject (readonly)

Returns the value of attribute direction.



3
4
5
# File 'lib/sorty_sorter/params.rb', line 3

def direction
  @direction
end

Instance Method Details

#optionsObject



17
18
19
# File 'lib/sorty_sorter/params.rb', line 17

def options
  Hash[sort_col, sort_dir]
end

#options!Object



21
22
23
# File 'lib/sorty_sorter/params.rb', line 21

def options!
  Hash[sort_col!, sort_dir!]
end