Class: Lazylead::CC

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/cc.rb

Overview

Entry point for email CC detection. The email may need CC email addresses, thus, there are various strategies

how it can be done.

Instance Method Summary collapse

Instance Method Details

#detect(emails, sys) ⇒ Object

Build an CC in order to detect email addresses by different conditions.

Supported conditions(types):

- PlainCC
- PredefinedCC
- ComponentCC
- Empty


39
40
41
42
43
44
45
46
# File 'lib/lazylead/cc.rb', line 39

def detect(emails, sys)
  return emails if recognized?(emails)
  return PlainCC.new(emails) if plain?(emails)
  return EmptyCC.new if undefined?(emails)
  type = emails["type"].constantize
  return ComponentCC.new(emails["project"], sys) if type.is_a? ComponentCC
  type.new(emails["opts"])
end

#plain?(text) ⇒ Boolean

Detect that raw CC is a string which may has plain email addresses

Returns:

  • (Boolean)


49
50
51
# File 'lib/lazylead/cc.rb', line 49

def plain?(text)
  (text.is_a? String) && text.to_s.include?("@")
end

#recognized?(emails) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/lazylead/cc.rb', line 53

def recognized?(emails)
  [EmptyCC, PlainCC, ComponentCC, PredefinedCC].member? emails.class
end

#undefined?(emails) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/lazylead/cc.rb', line 57

def undefined?(emails)
  return true unless emails.key? "type"
  emails["type"].nil? || emails["type"].blank?
end