Class: InboxSync::Config::Filter
- Inherits:
-
Object
- Object
- InboxSync::Config::Filter
- Defined in:
- lib/inbox-sync/config/filter.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
Instance Method Summary collapse
-
#initialize(conditions, &actions) ⇒ Filter
constructor
A new instance of Filter.
- #match?(message) ⇒ Boolean
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
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
6 7 8 |
# File 'lib/inbox-sync/config/filter.rb', line 6 def actions @actions end |
#conditions ⇒ Object (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
19 20 21 22 23 |
# File 'lib/inbox-sync/config/filter.rb', line 19 def match?() @conditions.keys.inject(true) do |result, key| result && value_matches?(.send(key), @conditions[key]) end end |