cost breakdowns for each resource
usage cost as reported by OnApp control panel
vm resources cost as reported by OnApp control panel
Default usage cost and vm resources cost to zero. Otherwise as OnappMarket::Bill::initialize
# File lib/onapp_market/onapp/bill.rb, line 19 def initialize(hash={}) @usage_cost = 0 @vm_resources_cost = 0 @cost_breakdown = parse_breakdown(hash[:raw_breakdown]) super(hash, TYPE) end
As OnappMarket::Bill::+, also sums #usage_cost and #vm_resources_cost
# File lib/onapp_market/onapp/bill.rb, line 27 def +(other) if other.kind_of? Enumerable other.inject(self) { |sum, bill| sum + bill } else @total_cost += other.total_cost @usage_cost += other.usage_cost @vm_resources_cost += other.vm_resources_cost @cost_breakdown = @cost_breakdown.merge(other.cost_breakdown) { |key, ours, theirs| ours + theirs } self end end
Rounds all totals to 4 DP
# File lib/onapp_market/onapp/bill.rb, line 48 def round @total_cost = @total_cost.round(4) @usage_cost = @usage_cost.round(4) @vm_resources_cost = @vm_resources_cost.round(4) @cost_breakdown.each { |key, value| @cost_breakdown[key] = value.round(4) } end
As OnappMarket::Bill::zero, also zeros #usage_cost and #vm_resources_cost
# File lib/onapp_market/onapp/bill.rb, line 40 def zero @total_cost = 0 @usage_cost = 0 @vm_resources_cost = 0 @cost_breakdown.each_key { |key| @cost_breakdown[key] = 0 } end