Class: InboxSync::Config::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/inbox-sync/config/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conditions, &actions) ⇒ Filter

Returns a new instance of Filter.



8
9
10
11
12
13
14
15
16
17
# File 'lib/inbox-sync/config/filter.rb', line 8

def initialize(conditions, &actions)
  @actions = actions

  # make sure all match conditions are regexps
  @conditions = conditions.keys.inject({}) do |processed, key|
    val = conditions[key]
    processed[key] = val.kind_of?(Regexp) ? val : /#{val.to_s}/
    processed
  end
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/inbox-sync/config/filter.rb', line 6

def actions
  @actions
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



6
7
8
# File 'lib/inbox-sync/config/filter.rb', line 6

def conditions
  @conditions
end

Instance Method Details

#match?(message) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/inbox-sync/config/filter.rb', line 19

def match?(message)
  @conditions.keys.inject(true) do |result, key|
    result && value_matches?(message.send(key), @conditions[key])
  end
end