Module: Fetcha::SortParams
- Defined in:
- lib/fetcha.rb
Class Method Summary collapse
Class Method Details
.convert_to_ordered_hash(fields) ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/fetcha.rb', line 176 def self.convert_to_ordered_hash(fields) fields.each_with_object({}) do |field, hash| if field.start_with?('-') field = field[1..-1] hash[field] = :desc else hash[field] = :asc end end end |
.sorted_fields(sort, allowed_set) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/fetcha.rb', line 167 def self.sorted_fields(sort, allowed_set) fields = sort.to_s.split(',') ordered_fields = convert_to_ordered_hash(fields) filtered_fields = ordered_fields.select { |k| allowed_set.include? k } filtered_fields.present? ? filtered_fields : nil end |