Class: SortableTable::SortTable
- Inherits:
-
Object
- Object
- SortableTable::SortTable
- Defined in:
- lib/sortable_table/models/sort_table.rb
Instance Attribute Summary collapse
-
#column_definitions ⇒ Object
readonly
Returns the value of attribute column_definitions.
-
#default_column ⇒ Object
readonly
Returns the value of attribute default_column.
-
#default_direction ⇒ Object
readonly
Returns the value of attribute default_direction.
Instance Method Summary collapse
-
#initialize(column_definitions, options = {}) ⇒ SortTable
constructor
A new instance of SortTable.
- #sort_column(column, direction) ⇒ Object
Constructor Details
#initialize(column_definitions, options = {}) ⇒ SortTable
Returns a new instance of SortTable.
5 6 7 8 9 10 11 12 |
# File 'lib/sortable_table/models/sort_table.rb', line 5 def initialize(column_definitions, = {}) @default_column = [:default_column] || column_definitions.first.column @default_direction = [:default_direction] || :asc @column_definitions = column_definitions.each_with_object({}) do |column_definition, acc| acc[column_definition.column] = column_definition acc end end |
Instance Attribute Details
#column_definitions ⇒ Object (readonly)
Returns the value of attribute column_definitions.
3 4 5 |
# File 'lib/sortable_table/models/sort_table.rb', line 3 def column_definitions @column_definitions end |
#default_column ⇒ Object (readonly)
Returns the value of attribute default_column.
3 4 5 |
# File 'lib/sortable_table/models/sort_table.rb', line 3 def default_column @default_column end |
#default_direction ⇒ Object (readonly)
Returns the value of attribute default_direction.
3 4 5 |
# File 'lib/sortable_table/models/sort_table.rb', line 3 def default_direction @default_direction end |
Instance Method Details
#sort_column(column, direction) ⇒ Object
14 15 16 17 |
# File 'lib/sortable_table/models/sort_table.rb', line 14 def sort_column(column, direction) column_definition = column_definitions[column] || column_definitions[default_column] column_definition.create_sort_column(direction || default_direction.to_s) end |