class Flexa::Invoice

Public Class Methods

define_filter(name) click to toggle source
# File lib/invoice/invoice.rb, line 13
def self.define_filter(name)
  hash = {
    amazonec2: 'AmazonEC2',
    amazonses: 'AmazonSES',
    amazonsns: 'AmazonSNS',
    amazonrds: 'AmazonRDS',
    amazons3: 'AmazonS3',
    amazonroute53: 'AmazonRoute53',
    awsdatatransfer: 'AWSDataTransfer',
    awsqueueservice: 'AWSQueueService'
  }
  define_method(name){ |client|
    @csv.find_all { |row| row['ProductCode'] == hash[name.to_sym] && row['user:Cliente'] == client }
  }
end
new(csv_file) click to toggle source
# File lib/invoice/invoice.rb, line 5
def initialize(csv_file)
  @csv = self.parse(csv_file)
end

Public Instance Methods

parse(csv_file) click to toggle source
# File lib/invoice/invoice.rb, line 8
def parse(csv_file)
  csv = CSV.read(csv_file, headers: true, converters: :numeric)
  csv.each
end
total(who, client) click to toggle source
# File lib/invoice/invoice.rb, line 29
def total(who, client)
  total = 0
  self.send(who, client).each{ |row| total += row['TotalCost'] }
  total.round(2)
end