Module: Fetcha::SortParams
- Defined in:
- lib/fetcha.rb
Class Method Summary collapse
Class Method Details
.convert_to_ordered_hash(fields) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fetcha.rb', line 156 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
147 148 149 150 151 152 153 154 |
# File 'lib/fetcha.rb', line 147 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 |