Class: ZeroDrop::Filter

Inherits:
Struct
  • Object
show all
Defined in:
lib/zerodrop.rb

Overview

Filter for narrowing which email is returned. All string matches are case-insensitive partial matches.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



52
53
54
# File 'lib/zerodrop.rb', line 52

def body
  @body
end

#fromObject

Returns the value of attribute from

Returns:

  • (Object)

    the current value of from



52
53
54
# File 'lib/zerodrop.rb', line 52

def from
  @from
end

Returns the value of attribute has_magic_link

Returns:

  • (Object)

    the current value of has_magic_link



52
53
54
# File 'lib/zerodrop.rb', line 52

def has_magic_link
  @has_magic_link
end

#has_otpObject

Returns the value of attribute has_otp

Returns:

  • (Object)

    the current value of has_otp



52
53
54
# File 'lib/zerodrop.rb', line 52

def has_otp
  @has_otp
end

#subjectObject

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



52
53
54
# File 'lib/zerodrop.rb', line 52

def subject
  @subject
end

Instance Method Details

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/zerodrop.rb', line 56

def matches?(email)
  return false if from && !email.from.to_s.downcase.include?(from.downcase)
  return false if subject && !email.subject.to_s.downcase.include?(subject.downcase)
  return false if body && !email.body.to_s.downcase.include?(body.downcase)

  unless has_otp.nil?
    return false if has_otp && email.otp.to_s.empty?
    return false if !has_otp && !email.otp.to_s.empty?
  end

  unless has_magic_link.nil?
    return false if has_magic_link && email.magic_link.to_s.empty?
    return false if !has_magic_link && !email.magic_link.to_s.empty?
  end

  true
end