Class: Margrid::Sorter
- Inherits:
-
Struct
- Object
- Struct
- Margrid::Sorter
- Defined in:
- lib/margrid/components.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#direction ⇒ Object
Returns the value of attribute direction.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(relation) ⇒ Object
- #asc? ⇒ Boolean
- #desc? ⇒ Boolean
- #dump ⇒ Object
-
#initialize(column, direction) ⇒ Sorter
constructor
A new instance of Sorter.
- #inverted ⇒ Object
Constructor Details
#initialize(column, direction) ⇒ Sorter
Returns a new instance of Sorter.
3 4 5 |
# File 'lib/margrid/components.rb', line 3 def initialize(column, direction) super column.to_s, direction.to_s end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column
2 3 4 |
# File 'lib/margrid/components.rb', line 2 def column @column end |
#direction ⇒ Object
Returns the value of attribute direction
2 3 4 |
# File 'lib/margrid/components.rb', line 2 def direction @direction end |
Class Method Details
.load(data) ⇒ Object
23 24 25 |
# File 'lib/margrid/components.rb', line 23 def self.load(data) new data["sort"], data["direction"] if data.key? "sort" end |
Instance Method Details
#apply(relation) ⇒ Object
7 8 9 |
# File 'lib/margrid/components.rb', line 7 def apply(relation) relation.reorder(sorting) end |
#asc? ⇒ Boolean
19 20 21 |
# File 'lib/margrid/components.rb', line 19 def asc? !desc? end |
#desc? ⇒ Boolean
15 16 17 |
# File 'lib/margrid/components.rb', line 15 def desc? direction == "desc" end |
#dump ⇒ Object
27 28 29 |
# File 'lib/margrid/components.rb', line 27 def dump {"sort" => column, "direction" => direction} end |
#inverted ⇒ Object
11 12 13 |
# File 'lib/margrid/components.rb', line 11 def inverted self.class.new(column, asc? ? :desc : :asc) end |