Skip to content

Commit

Permalink
Calculate key/values and report them in a single method
Browse files Browse the repository at this point in the history
This lowers the indirection and complexity.
  • Loading branch information
isimluk committed Oct 25, 2016
1 parent 94ae8bc commit e31d499
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ def calculate_costs(metric_rollup_records, rates, hours_in_interval)
cost = r.cost(metric_value) * hours_in_interval
end

reportable_metric_and_cost_fields(r.rate_name, r.group, metric_value, cost).each do |k, val|
next unless self.class.attribute_names.include?(k)
self[k] ||= 0
self[k] += val
end
reportable_metric_and_cost_fields(r.rate_name, r.group, metric_value, cost)
end
end
end
Expand All @@ -162,7 +158,11 @@ def reportable_metric_and_cost_fields(rate_name, rate_group, metric, cost)
[cost_key, cost_group_key, 'total_cost'].each { |col| col_hash[col] = cost }
end

col_hash
col_hash.each do |k, val|
next unless self.class.attribute_names.include?(k)
self[k] ||= 0
self[k] += val
end
end
private :reportable_metric_and_cost_fields

Expand Down

0 comments on commit e31d499

Please sign in to comment.