Module: Bearclaws

Defined in:
lib/bearclaws.rb,
lib/bearclaws/group.rb,
lib/bearclaws/charge.rb,
lib/bearclaws/mapping.rb,
lib/bearclaws/version.rb

Defined Under Namespace

Classes: Charge, Group

Constant Summary collapse

AWSMAP =

The mappings for a nomal AWS cost allocation report

{
  :invoice_id => 0,
  :payer_account_id => 1,
  :linked_account_id => 2,
  :charge_type => 3,
  :charge_id => 4,
  :billing_period_start_date => 5,
  :billing_period_end_date => 6,
  :invoice_date => 7,
  :payer_account_name => 8,
  :linked_account_name => 9,
  :taxation_address => 10,
  :payer_po_number => 11,
  :product_code => 12,
  :product_name => 13,
  :seller_of_charge => 14,
  :usage_type => 15,
  :operation => 16,
  :availability_zone => 17,
  :rate_id => 18,
  :item_description => 19,
  :usage_start_date => 20,
  :usage_end_date => 21,
  :usage_quantity => 22,
  :blended_rate => 23,
  :currency_code => 24,
  :cost_before_tax => 25,
  :credits => 26,
  :tax_amount => 27,
  :tax_type => 28,
  :total_cost => 29
}
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.analyze(file = nil, tag_column = nil) ⇒ Array

Analyze the output of you AWS cost allocation report. Group your costs by an arbitrary tag, like ‘client’

aws.amazon.com/about-aws/whats-new/2012/08/21/aws-billing-enables-cost-allocation-reports/

Parameters:

  • file (File) (defaults to: nil)

    a CSV of allocated AWS charges (i.e., 937951391671-aws-cost-allocation-2013-09.csv)

  • tag_column (Integer) (defaults to: nil)

    The zero-indexed column number in the CSV that holds the tag you want to group by

Returns:

  • (Array)

    A set of Bearclaws::Group objects grouped by tag



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bearclaws.rb', line 14

def self.analyze(file = nil, tag_column = nil)

  raise "No file supplied!" unless file
  raise "No CSV group column supplied!" unless tag_column
  raise "Group column must be an integer!" unless tag_column.is_a? Integer

  groups = { default: Bearclaws::Group.new(:default) }

  rows = CSV.parse file.read

  rows.shift(2) # remove instructions, column labels
  rows.pop(3)   # remove subtotal, total, footer

  rows.each do |row|
    name = (row[tag_column].nil?) ? :default : row[tag_column]
    groups[name] ||= Bearclaws::Group.new(name.to_sym)
    groups[name].charges << Bearclaws::Charge.new(row)
  end

  return groups.collect { |k, v| v }
end