Module: Siren::JsonQuery::SortFilter

Defined in:
lib/siren/json_query_nodes.rb

Instance Method Summary collapse

Instance Method Details

#value(list, root, symbols, current = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/siren/json_query_nodes.rb', line 140

def value(list, root, symbols, current = nil)
  sorters = [[first.expression, first.sorter]] +
            others.elements.map { |e| [e.expression, e.sorter] }
  
  list.sort do |a, b|
    sorters.inject(0) do |outcome, sorter|
      if outcome.nonzero?
        outcome
      else
        f, g = sorter[0].value(root, symbols, a), sorter[0].value(root, symbols, b)
        sorter[1].value * (f <=> g)
      end
    end
  end
end