class GmailBritta::NegatedChainingFilter

Public Class Methods

new(parent) click to toggle source
Calls superclass method GmailBritta::ChainingFilter::new
# File lib/gmail-britta/chaining_filter.rb, line 33
def initialize(parent)
  super
end

Public Instance Methods

deep_invert(has_not, has) click to toggle source
# File lib/gmail-britta/chaining_filter.rb, line 54
def deep_invert(has_not, has)
  case
  when has_not.first.is_a?(Hash) && has_not.first[:or]
    has_not.first[:or] += has
    has_not
  when has_not.length > 0
    [{:or => has_not + has}]
  else
    has
  end
end
invert(old) click to toggle source
# File lib/gmail-britta/chaining_filter.rb, line 44
def invert(old)
  old.map! do |addr|
    if addr[0] == '-'
      addr[1..-1]
    else
      '-' + addr
    end
  end
end
load(name, filter) click to toggle source
# File lib/gmail-britta/chaining_filter.rb, line 38
def load(name, filter)
  filter.send("get_#{name}").reject do |elt|
    instance_variable_get("@#{name}").member?(elt)
  end
end
perform_merge(filter) click to toggle source
# File lib/gmail-britta/chaining_filter.rb, line 37
def perform_merge(filter)
  def load(name, filter)
    filter.send("get_#{name}").reject do |elt|
      instance_variable_get("@#{name}").member?(elt)
    end
  end

  def invert(old)
    old.map! do |addr|
      if addr[0] == '-'
        addr[1..-1]
      else
        '-' + addr
      end
    end
  end

  def deep_invert(has_not, has)
    case
    when has_not.first.is_a?(Hash) && has_not.first[:or]
      has_not.first[:or] += has
      has_not
    when has_not.length > 0
      [{:or => has_not + has}]
    else
      has
    end
  end

  @to += invert(load(:to, filter))
  @from += invert(load(:from, filter))
  @has_not += deep_invert(load(:has_not, filter), load(:has, filter))
end