Module: Fetcha::SortParams
- Defined in:
- lib/fetcha.rb
Class Method Summary collapse
Class Method Details
.convert_to_ordered_hash(fields) ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/fetcha.rb', line 161 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
152 153 154 155 156 157 158 159 |
# File 'lib/fetcha.rb', line 152 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 |