From 6c172d9b8e028c3d998d6d5cf5b85e5980cad6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Thu, 27 Oct 2016 10:05:34 +0200 Subject: [PATCH] Refactor: Extract method: metric_and_cost_by --- app/models/chargeback.rb | 4 +--- app/models/chargeback_rate_detail.rb | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/chargeback.rb b/app/models/chargeback.rb index d1bfacc1fd7..6894b1a413a 100644 --- a/app/models/chargeback.rb +++ b/app/models/chargeback.rb @@ -144,9 +144,7 @@ def calculate_costs(metric_rollup_records, rates, hours_in_interval) if !chargeback_fields_present && r.fixed? cost = 0 else - r.hours_in_interval = hours_in_interval - metric_value = r.metric_value_by(metric_rollup_records) - cost = r.hourly_cost(metric_value) * hours_in_interval + metric_value, cost = r.metric_and_cost_by(metric_rollup_records, hours_in_interval) end accumulate_metrics_and_costs_per_rate(r.rate_name, r.group, metric_value, cost) diff --git a/app/models/chargeback_rate_detail.rb b/app/models/chargeback_rate_detail.rb index ac99375788e..0a817cd7140 100644 --- a/app/models/chargeback_rate_detail.rb +++ b/app/models/chargeback_rate_detail.rb @@ -210,6 +210,12 @@ def contiguous_tiers? !error end + def metric_and_cost_by(metric_rollup_records, hours_in_interval) + @hours_in_interval = hours_in_interval + metric_value = metric_value_by(metric_rollup_records) + [metric_value, hourly_cost(metric_value) * hours_in_interval] + end + private def first_tier?(tier,tiers)