Class: MundaneSearch::Filters::MultiOrder
- Defined in:
- lib/mundane-search/filters/multi_order.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ActiveRecord
Instance Attribute Summary
Attributes inherited from Base
#collection, #options, #params
Instance Method Summary collapse
Methods inherited from Typical
#apply?, #key, key_type, #key_type, key_types, #match_value, #optional?, #target
Methods inherited from Base
#apply?, #call, #filtered_params, #initialize
Constructor Details
This class inherits a constructor from MundaneSearch::Filters::Base
Instance Method Details
#filtered_collection ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mundane-search/filters/multi_order.rb', line 25 def filtered_collection collection.reverse.sort do |a,b| compare = ordering_pairs.inject([[],[]]) do |sum, pair| attribute, direction = pair attribute = :"#{attribute}" if ascending_terms.include?(direction) sum.first << a.send(attribute) sum.last << b.send(attribute) else sum.first << b.send(attribute) sum.last << a.send(attribute) end sum end compare.first <=> compare.last end end |