Class: WcoEmail::EmailFilterCondition
- Inherits:
-
Object
- Object
- WcoEmail::EmailFilterCondition
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/wco_email/email_filter_condition.rb
Constant Summary collapse
- FIELD_BODY =
'body'- FIELD_BODY_PLAIN =
'body-plain'- FIELD_FROM =
'from'- FIELD_LEADSET =
'from-leadset'- FIELD_SUBJECT =
'subject'- FIELD_TAGGED =
either lead or leadset, actually
'leadset-tagged'- FIELD_NOT_TAGGED =
either lead or leadset, actually
'leadset-not-tagged'- FIELD_TO_OR_CC =
'to-or-cc'- FIELD_OPTS =
[ FIELD_BODY, FIELD_BODY_PLAIN, FIELD_FROM, FIELD_LEADSET, FIELD_SUBJECT, FIELD_TAGGED, FIELD_NOT_TAGGED, FIELD_TO_OR_CC, ]
- OPERATOR_EQUALS =
'eq-i'- OPERATOR_HAS_TAG =
'has-tag'- OPERATOR_NOT_HAS_TAG =
'not-has-tag'- OPERATOR_REGEX =
'regex'- OPERATOR_MATCH =
'match-i'- OPERATOR__ID =
'_id'- OPERATOR_SLUG =
'slug'- OPERATOR_OPTS =
[ OPERATOR__ID, OPERATOR_EQUALS, OPERATOR_HAS_TAG, OPERATOR_MATCH, OPERATOR_NOT_HAS_TAG, OPERATOR_REGEX, OPERATOR_SLUG, ]
Instance Method Summary collapse
Instance Method Details
#apply(lead:, message:) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/wco_email/email_filter_condition.rb', line 52 def apply lead:, message: cond = self reason = nil case cond.field ## from match-i <value> when WcoEmail::EmailFilterCondition::FIELD_FROM if cond.operator == WcoEmail::EmailFilterCondition::OPERATOR_MATCH if .from.downcase.include?( value.downcase ) reason = "#{email_skip_filter ? 'skip_' : ''}condition from match-i `#{value}`" end end when WcoEmail::EmailFilterCondition::FIELD_TAGGED ## cond.operator should eql OPERATOR__ID but I don't check b/c if its slug, it should work also. tag = Wco::Tag.find( cond.value ) rescue nil tag ||= Wco::Tag.where( slug: cond.value ).first if tag if lead.leadset..include?( tag ) || lead..include?( tag ) reason = "#{email_skip_filter ? 'skip_' : ''}condition TAGGED `#{tag.slug}`" end end when WcoEmail::EmailFilterCondition::FIELD_NOT_TAGGED ## cond.operator should eql OPERATOR__ID but I don't check b/c if its slug, it should work also. tag = Wco::Tag.find( cond.value ) rescue nil tag ||= Wco::Tag.where( slug: cond.value ).first if tag if !lead.leadset..include?( tag ) && !lead..include?( tag ) reason = "#{email_skip_filter ? 'skip_' : ''}condition NOT_TAGGED `#{tag.slug}`" end end end ## end case return reason end |
#to_s ⇒ Object
97 98 99 |
# File 'app/models/wco_email/email_filter_condition.rb', line 97 def to_s "<EF#{email_skip_filter ? 'Skip' : ''}Condition #{field} #{operator} `#{value}` />" end |
#to_s_full(indent: 0) ⇒ Object
100 101 102 |
# File 'app/models/wco_email/email_filter_condition.rb', line 100 def to_s_full indent: 0 "#{" " * indent }<EF#{email_skip_filter ? 'Skip' : ''}Condition #{field} #{operator} `#{value}` />\n" end |