Module: Profitable

Extended by:
ActionView::Helpers::NumberHelper
Defined in:
lib/profitable.rb,
lib/profitable/error.rb,
lib/profitable/engine.rb,
lib/profitable/version.rb,
lib/profitable/mrr_calculator.rb,
lib/profitable/numeric_result.rb,
lib/profitable/processors/base.rb,
app/controllers/profitable/base_controller.rb,
lib/profitable/processors/stripe_processor.rb,
lib/profitable/processors/braintree_processor.rb,
app/controllers/profitable/dashboard_controller.rb,
lib/profitable/processors/paddle_billing_processor.rb,
lib/profitable/processors/paddle_classic_processor.rb

Defined Under Namespace

Modules: Processors Classes: BaseController, DashboardController, Engine, Error, MrrCalculator, NumericResult

Constant Summary collapse

DEFAULT_PERIOD =
30.days
MRR_MILESTONES =
[5, 10, 20, 30, 50, 75, 100, 200, 300, 400, 500, 1_000, 2_000, 3_000, 5_000, 10_000, 20_000, 30_000, 50_000, 83_333, 100_000, 250_000, 500_000, 1_000_000, 5_000_000, 10_000_000, 25_000_000, 50_000_000, 75_000_000, 100_000_000]
VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.active_subscribersObject



62
63
64
# File 'lib/profitable.rb', line 62

def active_subscribers
  NumericResult.new(calculate_active_subscribers, :integer)
end

.all_time_revenueObject



33
34
35
# File 'lib/profitable.rb', line 33

def all_time_revenue
  NumericResult.new(calculate_all_time_revenue)
end

.arrObject



25
26
27
# File 'lib/profitable.rb', line 25

def arr
  NumericResult.new(calculate_arr)
end

.average_revenue_per_customerObject



86
87
88
# File 'lib/profitable.rb', line 86

def average_revenue_per_customer
  NumericResult.new(calculate_average_revenue_per_customer)
end

.churn(in_the_last: DEFAULT_PERIOD) ⇒ Object



29
30
31
# File 'lib/profitable.rb', line 29

def churn(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_churn(in_the_last), :percentage)
end

.churned_customers(in_the_last: DEFAULT_PERIOD) ⇒ Object



74
75
76
# File 'lib/profitable.rb', line 74

def churned_customers(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_churned_customers(in_the_last), :integer)
end

.churned_mrr(in_the_last: DEFAULT_PERIOD) ⇒ Object



82
83
84
# File 'lib/profitable.rb', line 82

def churned_mrr(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_churned_mrr(in_the_last))
end

.estimated_valuation(multiplier = nil, at: nil, multiple: nil) ⇒ Object



49
50
51
52
# File 'lib/profitable.rb', line 49

def estimated_valuation(multiplier = nil, at: nil, multiple: nil)
  actual_multiplier = multiplier || at || multiple || 3
  NumericResult.new(calculate_estimated_valuation(actual_multiplier))
end

.lifetime_valueObject



90
91
92
# File 'lib/profitable.rb', line 90

def lifetime_value
  NumericResult.new(calculate_lifetime_value)
end

.mrrObject



21
22
23
# File 'lib/profitable.rb', line 21

def mrr
  NumericResult.new(MrrCalculator.calculate)
end

.mrr_growth(in_the_last: DEFAULT_PERIOD) ⇒ Object



94
95
96
# File 'lib/profitable.rb', line 94

def mrr_growth(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_mrr_growth(in_the_last))
end

.mrr_growth_rate(in_the_last: DEFAULT_PERIOD) ⇒ Object



98
99
100
# File 'lib/profitable.rb', line 98

def mrr_growth_rate(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_mrr_growth_rate(in_the_last), :percentage)
end

.new_customers(in_the_last: DEFAULT_PERIOD) ⇒ Object



66
67
68
# File 'lib/profitable.rb', line 66

def new_customers(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_new_customers(in_the_last), :integer)
end

.new_mrr(in_the_last: DEFAULT_PERIOD) ⇒ Object



78
79
80
# File 'lib/profitable.rb', line 78

def new_mrr(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_new_mrr(in_the_last))
end

.new_subscribers(in_the_last: DEFAULT_PERIOD) ⇒ Object



70
71
72
# File 'lib/profitable.rb', line 70

def new_subscribers(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_new_subscribers(in_the_last), :integer)
end

.recurring_revenue_in_period(in_the_last: DEFAULT_PERIOD) ⇒ Object



41
42
43
# File 'lib/profitable.rb', line 41

def recurring_revenue_in_period(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_recurring_revenue_in_period(in_the_last))
end

.recurring_revenue_percentage(in_the_last: DEFAULT_PERIOD) ⇒ Object



45
46
47
# File 'lib/profitable.rb', line 45

def recurring_revenue_percentage(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_recurring_revenue_percentage(in_the_last), :percentage)
end

.revenue_in_period(in_the_last: DEFAULT_PERIOD) ⇒ Object



37
38
39
# File 'lib/profitable.rb', line 37

def revenue_in_period(in_the_last: DEFAULT_PERIOD)
  NumericResult.new(calculate_revenue_in_period(in_the_last))
end

.time_to_next_mrr_milestoneObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/profitable.rb', line 102

def time_to_next_mrr_milestone
  current_mrr = (mrr.to_i)/100
  next_milestone = MRR_MILESTONES.find { |milestone| milestone > current_mrr }
  return "Congratulations! You've reached the highest milestone." unless next_milestone

  monthly_growth_rate = calculate_mrr_growth_rate / 100
  return "Unable to calculate. Need more data or positive growth." if monthly_growth_rate <= 0

  # Convert monthly growth rate to daily growth rate
  daily_growth_rate = (1 + monthly_growth_rate) ** (1.0 / 30) - 1

  # Calculate the number of days to reach the next milestone
  days_to_milestone = (Math.log(next_milestone.to_f / current_mrr) / Math.log(1 + daily_growth_rate)).ceil

  target_date = Time.current + days_to_milestone.days

  "#{days_to_milestone} days left to $#{number_with_delimiter(next_milestone)} MRR (#{target_date.strftime('%b %d, %Y')})"
end

.total_customersObject



54
55
56
# File 'lib/profitable.rb', line 54

def total_customers
  NumericResult.new(calculate_total_customers, :integer)
end

.total_subscribersObject



58
59
60
# File 'lib/profitable.rb', line 58

def total_subscribers
  NumericResult.new(calculate_total_subscribers, :integer)
end