Module: WhereExpFilter

Defined in:
lib/liquidum/liquid/filters/where_exp_filter.rb

Instance Method Summary collapse

Instance Method Details

#where_exp(input, variable, expression) ⇒ Object

Filters an array of objects against an expression

input - the object array variable - the variable to assign each item to in the expression expression - a Liquid comparison expression passed in as a string

Returns the filtered array of objects



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/liquidum/liquid/filters/where_exp_filter.rb', line 11

def where_exp(input, variable, expression)
  return input unless input.respond_to?(:select)

  input = input.values if input.is_a?(Hash) # FIXME

  condition = parse_condition(expression)
  @context.stack do
    input.select do |object|
      @context[variable] = object
      condition.evaluate(@context)
    end
  end || []
end