module Linner::Order
Public Instance Methods
order_by(ary)
click to toggle source
# File lib/linner/helper.rb, line 11 def order_by(ary) ary << "..." if not ary.include? "..." order_ary = ary.inject([[]]) do |a, x| x != "..." ? a.last << x : a<< []; a end order_by_direction(order_ary.first, :before) order_by_direction(order_ary.last, :after) self end
Private Instance Methods
order_by_direction(ary, direction)
click to toggle source
# File lib/linner/helper.rb, line 22 def order_by_direction(ary, direction) ary = ary.reverse if direction == :before ary.each do |f| next unless i = self.index {|x| x =~ /#{f}/i} item = self.delete_at i direction == :before ? self.unshift(item) : self.push(item) end end