Class: Getto::Params::Search::Sort
- Inherits:
-
Object
- Object
- Getto::Params::Search::Sort
- Defined in:
- lib/getto/params/search.rb
Defined Under Namespace
Classes: Order
Instance Method Summary collapse
-
#initialize(sort:) ⇒ Sort
constructor
A new instance of Sort.
- #to_h {|Order.new(spec)| ... } ⇒ Object
Constructor Details
#initialize(sort:) ⇒ Sort
Returns a new instance of Sort.
47 48 49 |
# File 'lib/getto/params/search.rb', line 47 def initialize(sort:) @sort = [sort.split(".")].to_h end |
Instance Method Details
#to_h {|Order.new(spec)| ... } ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/getto/params/search.rb', line 51 def to_h spec = {} yield Order.new(spec) result = { column: nil, order: true, } spec.map{|key,is_straight| if sort = @sort[key] result[:column] = key.to_sym result[:order] = if sort == "asc" is_straight else not is_straight end end } result end |