Module: Fetcha::SortParams
- Defined in:
- lib/fetcha.rb
Class Method Summary collapse
Class Method Details
.convert_to_ordered_hash(fields) ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/fetcha.rb', line 180 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
171 172 173 174 175 176 177 178 |
# File 'lib/fetcha.rb', line 171 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 |