Skip to content

Commit

Permalink
Rename cost to hourly_cost
Browse files Browse the repository at this point in the history
As it better describes what it does. It calculates hourly cost for a
given metric.
  • Loading branch information
isimluk committed Nov 15, 2016
1 parent d8e04ee commit 16d00c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def calculate_costs(metric_rollup_records, rates, hours_in_interval)
else
r.hours_in_interval = hours_in_interval
metric_value = r.metric_value_by(metric_rollup_records)
cost = r.cost(metric_value) * hours_in_interval
cost = r.hourly_cost(metric_value) * hours_in_interval
end

accumulate_metrics_and_costs_per_rate(r.rate_name, r.group, metric_value, cost)
Expand Down
2 changes: 1 addition & 1 deletion app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def find_rate(value)
:yearly => "Year"
}

def cost(value)
def hourly_cost(value)
return 0.0 unless self.enabled?

value = 1.0 if fixed?
Expand Down
10 changes: 5 additions & 5 deletions spec/models/chargeback_rate_detail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

let(:hours_in_month) { 720 }

it "#cost" do
it '#hourly_cost' do
cvalue = 42.0
fixed_rate = 5.0
variable_rate = 8.26
Expand All @@ -46,13 +46,13 @@
:fixed_rate => fixed_rate,
:variable_rate => variable_rate)
cbd.update(:chargeback_tiers => [cbt])
expect(cbd.cost(cvalue)).to eq(cvalue * cbd.hourly(variable_rate) + cbd.hourly(fixed_rate))
expect(cbd.hourly_cost(cvalue)).to eq(cvalue * cbd.hourly(variable_rate) + cbd.hourly(fixed_rate))

cbd.group = 'fixed'
expect(cbd.cost(cvalue)).to eq(cbd.hourly(variable_rate) + cbd.hourly(fixed_rate))
expect(cbd.hourly_cost(cvalue)).to eq(cbd.hourly(variable_rate) + cbd.hourly(fixed_rate))

cbd.enabled = false
expect(cbd.cost(cvalue)).to eq(0.0)
expect(cbd.hourly_cost(cvalue)).to eq(0.0)
end

it "#hourly" do
Expand Down Expand Up @@ -195,7 +195,7 @@
:per_time => 'monthly',
:chargeback_rate_detail_measure_id => cbdm.id,
:hours_in_interval => hours_in_month)
expect(cbd_bytes.cost(100)).to eq(cbd_gigabytes.cost(100))
expect(cbd_bytes.hourly_cost(100)).to eq(cbd_gigabytes.hourly_cost(100))
end

it "#show_rates" do
Expand Down

0 comments on commit 16d00c3

Please sign in to comment.