Class: EmailPredictor::Rules

Inherits:
Base
  • Object
show all
Defined in:
lib/email_predictor/rules.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#validate!

Constructor Details

#initialize(opts = {}) ⇒ Rules

Returns a new instance of Rules.



7
8
9
10
11
# File 'lib/email_predictor/rules.rb', line 7

def initialize(opts = {})
  super
  @username = opts[:username]
  validate!
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/email_predictor/rules.rb', line 5

def name
  @name
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/email_predictor/rules.rb', line 5

def username
  @username
end

Class Method Details

.get(employees) ⇒ Object



70
71
72
73
74
75
# File 'lib/email_predictor/rules.rb', line 70

def get(employees)
  employees.collect do |employee|
    rule = new(employee)
    rule.predict
  end.uniq
end

Instance Method Details

#first_initial_dot_last_initialObject



29
30
31
# File 'lib/email_predictor/rules.rb', line 29

def first_initial_dot_last_initial
  "#{first_name_initial}.#{last_name_initial}"
end

#first_initial_dot_last_nameObject



25
26
27
# File 'lib/email_predictor/rules.rb', line 25

def first_initial_dot_last_name
  "#{first_name_initial}.#{last_name}"
end

#first_nameObject



33
34
35
# File 'lib/email_predictor/rules.rb', line 33

def first_name
  @name.split(' ').first
end

#first_name_dot_last_initialObject



21
22
23
# File 'lib/email_predictor/rules.rb', line 21

def first_name_dot_last_initial
  "#{first_name}.#{last_name_initial}"
end

#first_name_dot_last_nameObject



17
18
19
# File 'lib/email_predictor/rules.rb', line 17

def first_name_dot_last_name
  "#{first_name}.#{last_name}"
end

#first_name_initialObject



41
42
43
# File 'lib/email_predictor/rules.rb', line 41

def first_name_initial
  first_name[0,1]
end

#last_nameObject



37
38
39
# File 'lib/email_predictor/rules.rb', line 37

def last_name
  @name.split(' ').last
end

#last_name_initialObject



45
46
47
# File 'lib/email_predictor/rules.rb', line 45

def last_name_initial
  last_name[0,1]
end

#predictObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/email_predictor/rules.rb', line 57

def predict
  if first_name.eql?(username_first) && last_name.eql?(username_last)
    'first_name_dot_last_name'
  elsif first_name_initial.eql?(username_first) && last_name.eql?(username_last)
    'first_initial_dot_last_name'
  elsif first_name_initial.eql?(username_first) && last_name_initial.eql?(username_last)
    'first_initial_dot_last_initial'
  elsif first_name.eql?(username_first) && last_name_initial.eql?(username_last)
    'first_name_dot_last_initial'
  end
end

#some_fake_ruleObject



13
14
15
# File 'lib/email_predictor/rules.rb', line 13

def some_fake_rule
  "Holla!"
end

#username_firstObject



49
50
51
# File 'lib/email_predictor/rules.rb', line 49

def username_first
  @username.split('.').first
end

#username_lastObject



53
54
55
# File 'lib/email_predictor/rules.rb', line 53

def username_last
  @username.split('.').last
end