# File lib/ruote/util/filter.rb, line 137
    def initialize(hash, rule)

      @hash = hash
      @rule = rule

      fl = @rule['fields'] || @rule['field'] || @rule['f']

      raise ArgumentError.new(
        "filter is missing a 'fields', 'field' or 'f' arg at #{@rule.inspect}"
      ) unless fl

      if fl.is_a?(String)
        fl = fl.gsub(/!/, '\.') if REGEX_IN_STRING.match(fl)
        fl = Ruote.regex_or_s(fl)
      end

      @fields = if fl.is_a?(Regexp)

        # when restoring, you look at the old keys, not the current ones

        keys = Ruote.flatten_keys(@rule['restore'] ? @hash['~~'] : @hash)
        keys = keys.reject { |k| TILDE.match(k) } unless RTILDE.match(fl.source)

        # now only keep the keys that match our regexp

        keys.each_with_object([]) { |k, a|
          m = fl.match(k)
          a << [ k, Ruote.lookup(@hash, k), m[1..-1] ] if m
        }

      elsif fl.is_a?(String) and PIPE_SPLIT.match(fl)

        fields = fl.split(PIPE_SPLIT).collect { |field|
          val = Ruote.lookup(@hash, field)
          val.nil? ? nil : [ field, val, nil ]
        }.compact

        fields.empty? ? [ [ fl, nil, nil ] ] : fields
          # if no fields where found, place fake fl field to force failure

      else

        (fl.is_a?(Array) ? fl : fl.to_s.split(COMMA_SPLIT)).collect { |field|
          [ field,  Ruote.lookup(@hash, field), nil ]
        }
      end
    end