Method: CloudCostTracker::Billing::AccountBillingPolicy#initialize

Defined in:
lib/cloud_cost_tracker/billing/account_billing_policy.rb

#initialize(resources, options = {}) ⇒ AccountBillingPolicy

Creates an object that implements the default account billing policy

Parameters:

  • resources (Array <Fog::Model>)

    the resources to bill for

  • options (Hash) (defaults to: {})

    optional parameters:

    • :logger - a Ruby Logger-compatible object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cloud_cost_tracker/billing/account_billing_policy.rb', line 13

def initialize(resources, options={})
  @log = options[:logger] || FogTracker.default_logger
  setup_resource_billing_agents(resources)
  # Initialize data structures for caching costs
  # the hourly cost for each resource, and billing agent
  @hourly_cost  = Hash.new # @hourly_cost[resource][agent]
  # the total cost for each resource, and billing agent
  @total_cost   = Hash.new # @total_cost[resource][agent]
  resources.each do |resource|
    @hourly_cost[resource] ||= Hash.new
    @total_cost[resource]  ||= Hash.new
  end
  @account = resources.first. # Save account info
end