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:, leadset:, 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/wco_email/email_filter_condition.rb', line 52 def apply lead:, leadset:, 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 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 !leadset..include?( tag ) && !lead..include?( tag ) reason = "#{email_skip_filter ? 'skip_' : ''}condition NOT_TAGGED `#{tag.slug}`" end end end ## end case # when WcoEmail::FIELD_LEADSET # if cond.operator == WcoEmail::OPERATOR_NOT_HAS_TAG # this_tag = Wco::Tag.find cond.value # if leadset.tags.include?( this_tag ) # ; # else # reason = "#{email_skip_filter ? 'skip_' : ''}condition leadset not-has-tag #{this_tag} NOT met" # end # end # when WcoEmail::FIELD_TO # if message.to == cond.value # reason = "{email_skip_filter ? 'skip_' : ''}condition to = #{cond.value}" # end # end return reason end |
#to_s ⇒ Object
111 112 113 |
# File 'app/models/wco_email/email_filter_condition.rb', line 111 def to_s "<EF#{email_skip_filter ? 'Skip' : ''}Condition #{field} #{operator} `#{value}` />" end |
#to_s_full(indent: 0) ⇒ Object
114 115 116 |
# File 'app/models/wco_email/email_filter_condition.rb', line 114 def to_s_full indent: 0 "#{" " * indent }<EF#{email_skip_filter ? 'Skip' : ''}Condition #{field} #{operator} `#{value}` />\n" end |