Module: APIHub::LeadScore::Score

Extended by:
Score
Included in:
Score
Defined in:
lib/apihub/lead_score/score.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



4
5
6
# File 'lib/apihub/lead_score/score.rb', line 4

def defaults
  @defaults
end

Instance Method Details

#calculate(result, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/apihub/lead_score/score.rb', line 19

def calculate(result, options = {})
  options = defaults.merge(options)

  score = 0.0

  return score unless result

  if person = result.person
    if person.avatar
      score += 5
    end

    if person.twitter.followers
      score += person.twitter.followers * options.twitter_followers_weight
    end

    if person.angellist.followers
      score += person.angellist.followers * options.angellist_followers_weight
    end

    if person.klout.score
      score += person.klout.score * options.klout_score_weight
    end
  end

  if company = result.company
    unless company.personal
      score += options.company_score
    end

    if company.raised
      score += company.raised *
                options.company_raised_weight
    end

    if company.employees
      score += company.employees *
                options.company_employees_weight
    end

    if company.alexa.globalRank
      score += 1 / (company.alexa.globalRank *
                options.company_alexa_rank_weight)
    end

    if company.google.rank && company.google.rank > 0
      score += 1 / (company.google.rank *
                options.company_google_rank_weight)
    end

    if company.twitter.followers
      score += company.twitter.followers *
                options.company_twitter_followers_weight
    end
  end

  score /= options.total_score

  [score.round(1), 1.0].min
end