Method: FilterTable::Table#where

Defined in:
lib/utils/filter.rb

#where(conditions = {}, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/utils/filter.rb', line 50

def where(conditions = {}, &block)
  return self if !conditions.is_a?(Hash)
  return self if conditions.empty? && !block_given?

  filters = ''
  table = @params
  conditions.each do |field, condition|
    filters += " #{field} == #{condition.inspect}"
    table = filter_lines(table, field, condition)
  end

  if block_given?
    table = table.find_all { |e| new_entry(e, '').instance_eval(&block) }
    src = Trace.new
    src.instance_eval(&block)
    filters += Trace.to_ruby(src)
  end

  self.class.new(@resource, table, @filters + filters)
end