Skip to content

Commit

Permalink
Refactor: Extract method: metric_and_cost_by
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Nov 15, 2016
1 parent b938855 commit 6c172d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 1 addition & 3 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6c172d9

Please sign in to comment.