Class: Nps::Calculator
- Inherits:
-
Object
- Object
- Nps::Calculator
- Defined in:
- lib/nps/calculator.rb
Instance Method Summary collapse
-
#initialize(ballot) ⇒ Calculator
constructor
Internal: Initialize a Net Promoter Score (NPS) calculator.
-
#percentage_of_detractors ⇒ Object
Internal: The percentage of detractor votes in the ballot.
-
#percentage_of_passives ⇒ Object
Internal: The percentage of passive votes in the ballot.
-
#percentage_of_promoters ⇒ Object
Internal: The percentage of promoter votes in the ballot.
-
#score ⇒ Object
Internal: The Net Promoter Score (NPS) calculated from the ballot.
Constructor Details
#initialize(ballot) ⇒ Calculator
Internal: Initialize a Net Promoter Score (NPS) calculator
ballot - a ballot of votes in the NPS survey.
7 8 9 |
# File 'lib/nps/calculator.rb', line 7 def initialize(ballot) @ballot = ballot end |
Instance Method Details
#percentage_of_detractors ⇒ Object
Internal: The percentage of detractor votes in the ballot.
27 28 29 |
# File 'lib/nps/calculator.rb', line 27 def percentage_of_detractors @ballot.any_votes? ? ((detractors.to_f / @ballot.total_votes.to_f) * 100.0).round(2) : 0.0 end |
#percentage_of_passives ⇒ Object
Internal: The percentage of passive votes in the ballot.
22 23 24 |
# File 'lib/nps/calculator.rb', line 22 def percentage_of_passives @ballot.any_votes? ? ((passives.to_f / @ballot.total_votes.to_f) * 100.0).round(2) : 0.0 end |
#percentage_of_promoters ⇒ Object
Internal: The percentage of promoter votes in the ballot.
17 18 19 |
# File 'lib/nps/calculator.rb', line 17 def percentage_of_promoters @ballot.any_votes? ? ((promoters.to_f / @ballot.total_votes.to_f) * 100.0).round(2) : 0.0 end |
#score ⇒ Object
Internal: The Net Promoter Score (NPS) calculated from the ballot.
12 13 14 |
# File 'lib/nps/calculator.rb', line 12 def score percentage_of_promoters - percentage_of_detractors end |