Skip to content

Commit

Permalink
Make reportable_metric_and_cost_fields private instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Oct 25, 2016
1 parent 6c980f0 commit 94ae8bc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def calculate_costs(metric_rollup_records, rates, hours_in_interval)
cost = r.cost(metric_value) * hours_in_interval
end

self.class.reportable_metric_and_cost_fields(r.rate_name, r.group, metric_value, cost).each do |k, val|
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
Expand All @@ -147,15 +147,15 @@ def calculate_costs(metric_rollup_records, rates, hours_in_interval)
end
end

def self.reportable_metric_and_cost_fields(rate_name, rate_group, metric, cost)
def reportable_metric_and_cost_fields(rate_name, rate_group, metric, cost)
cost_key = "#{rate_name}_cost" # metric cost value (e.g. Storage [Used|Allocated|Fixed] Cost)
metric_key = "#{rate_name}_metric" # metric value (e.g. Storage [Used|Allocated|Fixed])
cost_group_key = "#{rate_group}_cost" # for total of metric's costs (e.g. Storage Total Cost)
metric_group_key = "#{rate_group}_metric" # for total of metrics (e.g. Storage Total)

col_hash = {}

defined_column_for_report = (report_col_options.keys & [metric_key, cost_key]).present?
defined_column_for_report = (self.class.report_col_options.keys & [metric_key, cost_key]).present?

if defined_column_for_report
[metric_key, metric_group_key].each { |col| col_hash[col] = metric }
Expand All @@ -164,6 +164,7 @@ def self.reportable_metric_and_cost_fields(rate_name, rate_group, metric, cost)

col_hash
end
private :reportable_metric_and_cost_fields

def self.report_cb_model(model)
model.gsub(/^Chargeback/, "")
Expand Down

0 comments on commit 94ae8bc

Please sign in to comment.