Class: EmailPredictor::Predictor

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

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#validate!

Constructor Details

#initialize(opts = {}) ⇒ Predictor

Returns a new instance of Predictor.



11
12
13
14
15
16
# File 'lib/email_predictor/predictor.rb', line 11

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

Instance Attribute Details

#companyObject (readonly)

Returns the value of attribute company.



9
10
11
# File 'lib/email_predictor/predictor.rb', line 9

def company
  @company
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/email_predictor/predictor.rb', line 9

def message
  @message
end

#predicted_emailsObject (readonly)

Returns the value of attribute predicted_emails.



9
10
11
# File 'lib/email_predictor/predictor.rb', line 9

def predicted_emails
  @predicted_emails
end

Class Method Details

.predict(opts) ⇒ Object



19
20
21
22
# File 'lib/email_predictor/predictor.rb', line 19

def predict(opts)
  obj = new(opts).predict
  obj
end

Instance Method Details

#applicable_rulesObject



38
39
40
41
# File 'lib/email_predictor/predictor.rb', line 38

def applicable_rules
  data_analyser = EmailPredictor::DataAnalyser.find(@company)
  data_analyser ? data_analyser.rules : []
end

#predictObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/email_predictor/predictor.rb', line 25

def predict
  obj = EmailPredictor::Rules.new(name: @name)
  unless applicable_rules.empty?
    applicable_rules.collect do |rule|
      @predicted_emails << "#{obj.send(rule)}@#{@company}.com"
      @message = 'Successfully predicted emails.'
    end
  else
    @message = "Prediction cannot be done for #{@name.titleize} as we don't have any historical data for #{@company} company."
  end
  self
end