Class: Testimonials::NpsResponse

Inherits:
ApplicationRecord show all
Defined in:
app/models/testimonials/nps_response.rb

Overview

One answer to "How likely are you to recommend us?" (0–10).

Constant Summary collapse

THIN_SAMPLE =

Below this many responses a single answer swings the score by several points, so the dashboard says so instead of implying the number is solid.

30

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.band(nps) ⇒ Object

The industry-standard reading of an NPS number, so the dashboard can say whether a score is good without anyone having to go and google it.



27
28
29
30
31
32
33
34
35
36
# File 'app/models/testimonials/nps_response.rb', line 27

def self.band(nps)
  return nil if nps.nil?

  case nps
  when ...0 then :needs_work
  when 0...30 then :good
  when 30...70 then :great
  else :excellent
  end
end

.score(scope = all) ⇒ Object

The classic Net Promoter Score: %promoters − %detractors, −100..100.



16
17
18
19
20
21
22
23
# File 'app/models/testimonials/nps_response.rb', line 16

def self.score(scope = all)
  total = scope.count
  return nil if total.zero?

  promoters = scope.where(score: 9..10).count
  detractors = scope.where(score: 0..6).count
  ((promoters - detractors) * 100.0 / total).round
end

Instance Method Details

#detractor?Boolean

Returns:

  • (Boolean)


13
# File 'app/models/testimonials/nps_response.rb', line 13

def detractor? = score <= 6

#passive?Boolean

Returns:

  • (Boolean)


12
# File 'app/models/testimonials/nps_response.rb', line 12

def passive? = score.between?(7, 8)

#promoter?Boolean

Returns:

  • (Boolean)


11
# File 'app/models/testimonials/nps_response.rb', line 11

def promoter? = score >= 9