Module: Deli::Param::Order

Instance Method Summary collapse

Instance Method Details

#order_hash(value) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/deli/param.rb', line 116

def order_hash(value)
  value.split(",").inject(ActiveSupport::OrderedHash.new) do |hash, string|
    string.scan(/([\w-]+[^\-\+])([\+\-])?/).each do |token, operator|
      hash[clean(token)] = operator == "-" ? "-" : "+"
    end
    hash
  end
end

#parse(value) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/deli/param.rb', line 100

def parse(value)
  value.split(",").map do |string|
    string.scan(/([\w-]+[^\-\+])([\+\-])?/).map do |token, operator|
      operator = operator == "-" ? "-" : "+"
      token    = clean(token)
      
      if controller.present?
        param = controller.find(token)
        token = param.table_key
      end

      {:namespace => namespace, :key => token, :operators => [operator]}
    end
  end.flatten
end