class OnappMarket::Bill

A generic ‘bill’ for resource usage over a period of time

Includes billing information for a particular time period Should not be instantiated, instead instantiate child classes for the particular instance types. Child classes will include whatever provider-specific billing information is available

Constants

ID
TYPE

Attributes

bill_id[RW]

Backend identifier for this bill

complete[RW]

Whether all bills for this period have been incorporated into this bill. Normally means the bill covers the entire billing period, but if the instance was created or destroyed during the period, it would be true iff the bill incorporates all sub-bills after creation and before destruction.

currency[RW]

Currency of the bill

instance_id[RW]

Instance covered by this bill

period[RW]

Billing period represented: hourly|daily|monthly. Daily and monthly bills are created by aggregating hourly bills across the billing period.

resource_id[RW]

Id of the resource owning the associated instance

start_time[RW]

Start of the billing period

supplier_id[RW]

Id of the supplier owning the associated instance

total_cost[RW]

Cost for the entire billing period. If complete is false, this value may not include all bills for the period, and may increase in future.

trader_id[RW]

Id of the trader owning the associated instance

Public Class Methods

namespace() click to toggle source
# File lib/onapp_market/bill.rb, line 55
def self.namespace
  Bill::TYPE
end
new(hash, type = nil) click to toggle source

Create a new bill, defaults to an incomplete bill with zero #total_cost

# File lib/onapp_market/bill.rb, line 45
def initialize(hash, type = nil)
  @currency = 'USD'
  @total_cost = 0

  type = TYPE if type == nil
  super(hash, type)

  restrict [:bill_id, :db_id], :admin
end

Public Instance Methods

+(other) click to toggle source

Sums the total cost with one or more other bills. Child classes should override this method to sum any other fields required

# File lib/onapp_market/bill.rb, line 61
def +(other)
  if other.kind_of? Enumerable
    other.inject(self) { |sum, bill| sum + bill }
  else
    @total_cost += other.total_cost
    self
  end
end
round() click to toggle source

Round total cost to 4 DP

# File lib/onapp_market/bill.rb, line 76
def round
  @total_cost = @total_cost.round(4)
end
zero() click to toggle source

Zero the total cost

# File lib/onapp_market/bill.rb, line 71
def zero
  @total_cost = 0
end