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
And convert camel case attributes to snake case one.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/senro/query_params_formatter.rb', line 14 def self.sorting(param) attributes = param.split(',') attributes.map do |attr| if /^\-/.match(attr).nil? "#{attr.strip.gsub(/^\+/, '').underscore} ASC" else "#{attr.strip.gsub(/^\-/, '').underscore} DESC" end end.join(', ') end |