Class: Totalizer::ChurnMessage

Inherits:
Message
  • Object
show all
Defined in:
lib/totalizer/message.rb

Instance Attribute Summary

Attributes inherited from Message

#description, #duration, #text

Instance Method Summary collapse

Methods inherited from Message

#percentage_string, #period_string

Constructor Details

#initialize(growth_metric, previous_activity_metric, this_activity_metc, duration) ⇒ ChurnMessage

Returns a new instance of ChurnMessage.



73
74
75
76
77
78
79
80
81
# File 'lib/totalizer/message.rb', line 73

def initialize growth_metric, previous_activity_metric, this_activity_metc, duration
  self.duration = duration

  new_and_existing = previous_activity_metric.value + growth_metric.value
  lost_existing = (previous_activity_metric.ids - this_activity_metc.ids).size
  final = new_and_existing - lost_existing
  self.text = "#{period_string}: #{percentage_string lost_existing.to_f / new_and_existing.to_f} (#{lost_existing}/#{new_and_existing})"
  self.description = Totalizer.descriptions.churn
end