Class: EmailPredictor::DataAnalyser
- Inherits:
-
Object
- Object
- EmailPredictor::DataAnalyser
- Defined in:
- lib/email_predictor/data_analyser.rb
Instance Attribute Summary collapse
-
#company ⇒ Object
readonly
Returns the value of attribute company.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
- .all ⇒ Object
-
.dataset ⇒ Object
Sample dataset TODO: should be flexible and via a .yml or .json file.
- .find(company) ⇒ Object
- .get_rules(employees) ⇒ Object
-
.group_by_company ⇒ Object
We need to group the dataset by the company and the number of people associated with it.
Instance Method Summary collapse
-
#initialize(opts) ⇒ DataAnalyser
constructor
A new instance of DataAnalyser.
Constructor Details
#initialize(opts) ⇒ DataAnalyser
Returns a new instance of DataAnalyser.
16 17 18 19 |
# File 'lib/email_predictor/data_analyser.rb', line 16 def initialize(opts) @company = opts[:company] @rules = opts[:rules] end |
Instance Attribute Details
#company ⇒ Object (readonly)
Returns the value of attribute company.
14 15 16 |
# File 'lib/email_predictor/data_analyser.rb', line 14 def company @company end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
14 15 16 |
# File 'lib/email_predictor/data_analyser.rb', line 14 def rules @rules end |
Class Method Details
.all ⇒ Object
22 23 24 25 26 27 28 |
# 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 ⇒ Object
Sample dataset TODO: should be flexible and via a .yml or .json file
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/email_predictor/data_analyser.rb', line 37 def dataset { 'John Ferguson' => '[email protected]', 'Damon Aw' => '[email protected]', 'Linda Li' => '[email protected]', 'Larry Page' => '[email protected]', 'Sergey Brin' => '[email protected]', 'Steve Jobs' => '[email protected]' } end |
.find(company) ⇒ Object
48 49 50 |
# File 'lib/email_predictor/data_analyser.rb', line 48 def find(company) all.find {|i| i.company == company} end |
.get_rules(employees) ⇒ Object
31 32 33 |
# File 'lib/email_predictor/data_analyser.rb', line 31 def get_rules(employees) EmailPredictor::Rules.get(employees) end |
.group_by_company ⇒ Object
We need to group the dataset by the company and the number of people associated with it
54 55 56 57 58 59 60 61 62 63 |
# 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 |