class EmailPredictor::DataAnalyser

Attributes

company[R]
rules[R]

Public Class Methods

all() click to toggle source
# File lib/email_predictor/data_analyser.rb, line 22
def all
  collection = []
  group_by_company.each_pair do |key,value|
    collection << new(company: key,rules: get_rules(value))
  end
  collection
end
dataset() click to toggle source

Sample dataset TODO: should be flexible and via a .yml or .json file

# File lib/email_predictor/data_analyser.rb, line 37
def dataset
  {
    'John Ferguson' => 'john.ferguson@alphasights.com',
    'Damon Aw'      => 'damon.aw@alphasights.com',
    'Linda Li'      => 'linda.li@alphasights.com',
    'Larry Page'    => 'larry.p@google.com',
    'Sergey Brin'   => 's.brin@google.com',
    'Steve Jobs'    => 's.j@apple.com'
  }
end
find(company) click to toggle source
# File lib/email_predictor/data_analyser.rb, line 48
def find(company)
  all.find {|i| i.company == company}
end
get_rules(employees) click to toggle source
# File lib/email_predictor/data_analyser.rb, line 31
def get_rules(employees)
  EmailPredictor::Rules.get(employees)
end
group_by_company() click to toggle source

We need to group the dataset by the company and the number of people associated with it

# File lib/email_predictor/data_analyser.rb, line 54
def group_by_company
  hsh = Hash.new
  dataset.each_pair do |key,value|
    company      = value.split('@')[1].split('.')[0] #get the company name
    username     = value.split('@')[0]
    hsh[company] ||= []
    hsh[company] << { name: key,username: username }
  end
  hsh
end
new(opts) click to toggle source
# File lib/email_predictor/data_analyser.rb, line 16
def initialize(opts)
  @company = opts[:company]
  @rules   = opts[:rules]
end