Class: WcoEmail::EmailFilterCondition

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
Defined in:
app/models/wco_email/email_filter_condition.rb

Instance Method Summary collapse

Instance Method Details

#apply(leadset:, message:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/wco_email/email_filter_condition.rb', line 21

def apply leadset:, message:
  cond = self
  reason = nil
  case cond.field
  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

#fieldObject

see WcoEmail::FIELD_*



12
# File 'app/models/wco_email/email_filter_condition.rb', line 12

field :field

#to_sObject



43
44
45
# File 'app/models/wco_email/email_filter_condition.rb', line 43

def to_s
  "<EFC #{field} #{operator} #{value} />"
end

#to_s_full(indent: 0) ⇒ Object



46
47
48
49
50
51
52
# File 'app/models/wco_email/email_filter_condition.rb', line 46

def to_s_full indent: 0
  _value = value
  if [ ::WcoEmail::OPERATOR_HAS_TAG, ::WcoEmail::OPERATOR_NOT_HAS_TAG ].include?( operator )
    _value = Wco::Tag.find( value )
  end
  "#{" " * indent }<EF#{email_skip_filter ? 'Skip' : ''}Condition #{field} #{operator} `#{_value}` />\n"
end