Class: Senro::QueryParamsFormatter
- Inherits:
-
Object
- Object
- Senro::QueryParamsFormatter
- Defined in:
- lib/senro/query_params_formatter.rb
Class Method Summary collapse
-
.sorting(param) ⇒ String
Format RESTful API’s query params to SQL order clause.
Class Method Details
.sorting(param) ⇒ String
Format RESTful API’s query params to SQL order clause. +: asc -: desc none(default): asc
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/senro/query_params_formatter.rb', line 12 def self.sorting(param) attributes = param.split(',') attributes.map do |attr| if /^\-/.match(attr).nil? "#{attr.strip.gsub(/^\+/, '')} ASC" else "#{attr.strip.gsub(/^\-/, '')} DESC" end end.join(', ') end |