Class: EmailPattern

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Serializable
Defined in:
app/models/email_pattern.rb

Class Method Summary collapse

Methods included from Serializable

#serialize_it, #serialized_object

Class Method Details

.identify(email) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/email_pattern.rb', line 14

def self.identify(email)
  all.each do |pattern|
    matchdata = email.match(/#{pattern.email_regexp}/)

    if matchdata
      matchdata_hash = matchdata.to_hash
      matchdata_hash[:email_pattern_id] = pattern.id
      matchdata_hash[:email] = email
      matchdata_hash[:organization_code] = pattern.organization_code
      matchdata_hash[:identity] = pattern.corresponded_identity
      matchdata_hash[:uid] = matchdata.to_s unless matchdata_hash.key?(:uid)

      matchdata_hash[:permit_changing_department_in_group] = pattern.permit_changing_department_in_group
      matchdata_hash[:permit_changing_department_in_organization] = pattern.permit_changing_department_in_organization
      matchdata_hash[:skip_confirmation] = pattern.skip_confirmation

      return parse_email_matches(matchdata_hash, pattern)
    end
  end
  return nil
end