Created
December 20, 2017 14:51
-
-
Save jeffreyjurgajtis/a4643dce499a33e225e1d630007a74e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MRR::Datapoint | |
# This class generates the `recurring_movement` object for an MRR datapoint. | |
class RecurringMovement | |
def initialize(datapoint, previous_datapoint) | |
@datapoint = datapoint | |
@previous_datapoint = previous_datapoint | |
end | |
def build | |
{ | |
category: category, | |
amount: amount, | |
description: description | |
} | |
end | |
private | |
def category | |
if %w(new_business churn reactivation).include?(datapoint.mrr_movement.category) | |
return datapoint.mrr_movement.category | |
end | |
if amount.positive? | |
"expansion" | |
elsif amount.negative? | |
"contraction" | |
else | |
"no_movement" | |
end | |
end | |
def amount | |
previous_movement_amount - current_subscription_items_mrr | |
end | |
def description | |
# CAN I PASS SUBSCRIPTION ITEMS TO CMOELS ACTIVITY GENERATOR RIGHT HERE???!!! | |
end | |
def previous_movement_amount | |
previous_datapoint.recurring_movement.amount | |
end | |
def subscription_items | |
datapoint.subscription.items.select(&:recurring?) | |
end | |
def current_subscription_items_mrr | |
subscription_items.sum { |item| item.mrr_movements.sum { |movement| movement["amount"] } } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment