class NoSE::Backend::Backend::FilterStatementStep

Perform filtering external to the backend

Public Class Methods

new(_client, _fields, _conditions, step, _next_step, _prev_step) click to toggle source
# File lib/nose/backend.rb, line 221
def initialize(_client, _fields, _conditions,
               step, _next_step, _prev_step)
  @step = step
end

Public Instance Methods

process(conditions, results) click to toggle source

Filter results by a list of fields given in the step @return [Array<Hash>]

# File lib/nose/backend.rb, line 228
def process(conditions, results)
  # Extract the equality conditions
  eq_conditions = conditions.values.select do |condition|
    !condition.range? && @step.eq.include?(condition.field)
  end

  # XXX: This assumes that the range filter step is the same as
  #      the one in the query, which is always true for now
  range = @step.range && conditions.each_value.find(&:range?)

  results.select! { |row| include_row?(row, eq_conditions, range) }

  results
end

Private Instance Methods

include_row?(row, eq_conditions, range) click to toggle source

Check if the row should be included in the result @return [Boolean]

# File lib/nose/backend.rb, line 247
def include_row?(row, eq_conditions, range)
  select = eq_conditions.all? do |condition|
    row[condition.field.id] == condition.value
  end

  if range
    range_check = row[range.field.id].method(range.operator)
    select &&= range_check.call range.value
  end

  select
end