flexa-aws-invoice 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +11 -0
- data/billing.csv +9 -0
- data/invoice.gemspec +21 -0
- data/lib/.~lock.billing.csv# +1 -0
- data/lib/invoice/array.rb +11 -0
- data/lib/invoice/invoice.rb +44 -0
- data/lib/invoice/version.rb +3 -0
- data/lib/invoice.rb +1 -0
- data/test/lib/invoice/array_test.rb +7 -0
- data/test/lib/invoice/invoice_test.rb +34 -0
- data/test/lib/invoice/version_test.rb +7 -0
- data/test/test_helper.rb +4 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b20cb9e958ae539ea31958b776e6c341c4ffcb0
|
4
|
+
data.tar.gz: fd05dc914c78b49602ca3395bb7d5c37708cddf8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0e930aeb4a0cc9394c3d8cab6ddb94b27dfeb33654949a8bdd97e8762ad05253221fdb13b5955f50ce32a39c48f41536c87da080690759a2c62e6e67b42cc45
|
7
|
+
data.tar.gz: 66ffb54f5017aaac222cf355984c4a3278bb4c6156557c63774291b5ad248a933442206594d93e85628b3cccf67806b1da82acb5b53aa6274cbce2dcb3f142b2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gil Gomes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Invoice
|
2
|
+
[![Code Climate](https://codeclimate.com/github/gil27/invoice.png)](https://codeclimate.com/github/gil27/invoice)
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'invoice'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install invoice
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/invoice/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/billing.csv
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
InvoiceID,PayerAccountId,LinkedAccountId,RecordType,RecordID,BillingPeriodStartDate,BillingPeriodEndDate,InvoiceDate,PayerAccountName,LinkedAccountName,TaxationAddress,PayerPONumber,ProductCode,ProductName,SellerOfRecord,UsageType,Operation,RateId,ItemDescription,UsageStartDate,UsageEndDate,UsageQuantity,BlendedRate,CurrencyCode,CostBeforeTax,Credits,TaxAmount,TaxType,TotalCost
|
2
|
+
38453548,899360400100,899360400100,LinkedLineItem,,2014/03/01 00:00:00,2014/03/31 23:59:59,2014/04/03 20:07:10,Flexait,Flexait,"Rua Leila Diniz 1 Ed Nina Sala 104, Nova Itaparica, VILA VELHA, Espirito Santo, 29104-215, BR",,AmazonSNS,Amazon Simple Notification Service,"Amazon Web Services, Inc.",SAE1-Requests-Tier1,,,"First 1,000,000 Amazon SNS API Requests per month are free",2014/03/01 00:00:00,2014/03/31 23:59:59,6.0,0.0,USD,0.000000,0.0,0.000000,None,0.000000
|
3
|
+
38453548,899360400100,899360400100,LinkedLineItem,,2014/03/01 00:00:00,2014/03/31 23:59:59,2014/04/03 20:07:10,Flexait,Flexait,"Rua Leila Diniz 1 Ed Nina Sala 104, Nova Itaparica, VILA VELHA, Espirito Santo, 29104-215, BR",,AWSDataTransfer,AWS Data Transfer,"Amazon Web Services, Inc.",SAE1-APN1-AWS-Out-Bytes,,,$0.000 per GB - data transfer out under the monthly global free tier,2014/03/01 00:00:00,2014/03/31 23:59:59,0.000147,0.0,USD,0.000000,0.0,0.000000,None,0.000000
|
4
|
+
38453548,899360400100,899360400100,LinkedLineItem,,2014/03/01 00:00:00,2014/03/31 23:59:59,2014/04/03 20:07:10,Flexait,Flexait,"Rua Leila Diniz 1 Ed Nina Sala 104, Nova Itaparica, VILA VELHA, Espirito Santo, 29104-215, BR",,AmazonRDS,Amazon RDS Service,"Amazon Web Services, Inc.",SAE1-InstanceUsage:db.m1.small,CreateDBInstance:0014,,$0.104 per RDS Small Instance hour (or partial hour) running PostgreSQL,2014/03/01 00:00:00,2014/03/31 23:59:59,342.0,104,USD,35.568000,0.0,0.000000,None,35.568000
|
5
|
+
38453548,899360400100,899360400100,LinkedLineItem,,2014/03/01 00:00:00,2014/03/31 23:59:59,2014/04/03 20:07:10,Flexait,Flexait,"Rua Leila Diniz 1 Ed Nina Sala 104, Nova Itaparica, VILA VELHA, Espirito Santo, 29104-215, BR",,AmazonEC2,Amazon Elastic Compute Cloud,"Amazon Web Services, Inc.",SAE1-BoxUsage:t1.micro,RunInstances,,$0.027 per Micro Instance (t1.micro) instance-hour (or partial hour),2014/03/01 00:00:00,2014/03/31 23:59:59,2232.0,0.0179274194,USD,40.014000,0.0,0.000000,None,40.014000
|
6
|
+
38453548,899360400100,,CBRounding,,2014/03/01 00:00:00,2014/03/31 23:59:59,2014/04/03 20:07:10,Flexait,,"Rua Leila Diniz 1 Ed Nina Sala 104, Nova Itaparica, VILA VELHA, Espirito Santo, 29104-215, BR",,,,,,,,There is a USD -0.022574 difference between the sum of all linked account totals and your invoice total.,,,,,USD,-0.022574,,,,-0.022574
|
7
|
+
38453548,899360400100,,InvoiceTotal,,2014/03/01 00:00:00,2014/03/31 23:59:59,2014/04/03 20:07:10,Flexait,,"Rua Leila Diniz 1 Ed Nina Sala 104, Nova Itaparica, VILA VELHA, Espirito Santo, 29104-215, BR",,,,,,,,Total amount for invoice 38453548,,,,,USD,410.55,0.0,0.000000,,410.55
|
8
|
+
,899360400100,899360400100,AccountTotal,,2014/03/01 00:00:00,2014/03/31 23:59:59,,Flexait,Flexait,,,,,,,,,Total for linked account# 899360400100 (Flexait),,,,,USD,410.572574,0.0,0.000000,,410.572574
|
9
|
+
,899360400100,,StatementTotal,,2014/03/01 00:00:00,2014/03/31 23:59:59,,Flexait,,,,,,,,,,Total statement amount for period 2014/03/01 00:00:00 - 2014/03/31 23:59:59,,,,,USD,410.55,0.0,0.000000,,410.55
|
data/invoice.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/invoice/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "flexa-aws-invoice"
|
6
|
+
spec.version = Invoice::VERSION
|
7
|
+
spec.authors = ["Gil Gomes"]
|
8
|
+
spec.email = ["gilgomesp@gmail.com"]
|
9
|
+
spec.summary = %q{Amazon CSV parser}
|
10
|
+
spec.description = %q{Gives the price based on the service.}
|
11
|
+
spec.homepage = 'http://github.com/gil27/invoice'
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
20
|
+
spec.add_development_dependency "rake",'~> 10.3'
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
flexa ,flexa,flexa-Vostro-3500,06.06.2014 15:36,file:///home/flexa/.config/libreoffice/3;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require_relative './array'
|
3
|
+
module Flexa
|
4
|
+
class Invoice
|
5
|
+
def initialize(csv_file, client = "")
|
6
|
+
@csv = self.parse(csv_file)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
def parse(csv_file)
|
10
|
+
CSV.read(csv_file, headers: true, converters: :numeric)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.define_filter(name)
|
14
|
+
hash = {
|
15
|
+
amazonec2: 'AmazonEC2',
|
16
|
+
amazonses: 'AmazonSES',
|
17
|
+
amazonsns: 'AmazonSNS',
|
18
|
+
amazonrds: 'AmazonRDS',
|
19
|
+
amazons3: 'AmazonS3',
|
20
|
+
amazonroute53: 'AmazonRoute53',
|
21
|
+
awsdatatransfer: 'AWSDataTransfer',
|
22
|
+
awsqueueservice: 'AWSQueueService'
|
23
|
+
}
|
24
|
+
define_method(name){
|
25
|
+
@csv.find_all { |row| row["ProductCode"] == hash[name.to_sym] && row['LinkedAccountName'] == @client }
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def total(who)
|
30
|
+
total = 0
|
31
|
+
self.send(who).each{ |row| total += row['TotalCost'] }
|
32
|
+
total.round(2)
|
33
|
+
end
|
34
|
+
|
35
|
+
define_filter :amazonec2
|
36
|
+
define_filter :amazonses
|
37
|
+
define_filter :awsdatatransfer
|
38
|
+
define_filter :amazonsns
|
39
|
+
define_filter :amazonrds
|
40
|
+
define_filter :amazons3
|
41
|
+
define_filter :amazonroute53
|
42
|
+
define_filter :awsqueueservice
|
43
|
+
end
|
44
|
+
end
|
data/lib/invoice.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative './invoice/invoice'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Flexa::Invoice do
|
4
|
+
it "must be defined" do
|
5
|
+
Invoice::VERSION.wont_be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:invoice){ Flexa::Invoice.new("billing.csv", "Flexait") }
|
9
|
+
|
10
|
+
it { invoice.must_respond_to(:parse) }
|
11
|
+
it { invoice.must_respond_to(:amazonec2) }
|
12
|
+
it { invoice.must_respond_to(:amazonses) }
|
13
|
+
it { invoice.must_respond_to(:amazonrds) }
|
14
|
+
it { invoice.must_respond_to(:parse) }
|
15
|
+
it { invoice.must_respond_to(:amazonec2) }
|
16
|
+
it { invoice.must_respond_to(:amazonses) }
|
17
|
+
it { invoice.must_respond_to(:total) }
|
18
|
+
it { invoice.amazonec2.must_be_instance_of(Array) }
|
19
|
+
|
20
|
+
it "#total" do
|
21
|
+
invoice.total(:amazonec2).must_be_instance_of(Float)
|
22
|
+
invoice.amazonec2.total_price.must_be_instance_of(Float)
|
23
|
+
|
24
|
+
invoice.total(:amazonec2).must_equal(40.01)
|
25
|
+
invoice.amazonec2.total_price.must_equal(40.01)
|
26
|
+
end
|
27
|
+
it "#amazonec2" do
|
28
|
+
invoice.amazonec2.first.must_be_instance_of(CSV::Row)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Can use Strings too" do
|
32
|
+
invoice.total(:amazonec2).must_equal invoice.total("amazonec2")
|
33
|
+
end
|
34
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flexa-aws-invoice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gil Gomes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.5'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '10.3'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
description: Gives the price based on the service.
|
42
|
+
email:
|
43
|
+
- gilgomesp@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- billing.csv
|
54
|
+
- invoice.gemspec
|
55
|
+
- lib/.~lock.billing.csv#
|
56
|
+
- lib/invoice.rb
|
57
|
+
- lib/invoice/array.rb
|
58
|
+
- lib/invoice/invoice.rb
|
59
|
+
- lib/invoice/version.rb
|
60
|
+
- test/lib/invoice/array_test.rb
|
61
|
+
- test/lib/invoice/invoice_test.rb
|
62
|
+
- test/lib/invoice/version_test.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
homepage: http://github.com/gil27/invoice
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.2.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Amazon CSV parser
|
88
|
+
test_files:
|
89
|
+
- test/lib/invoice/array_test.rb
|
90
|
+
- test/lib/invoice/invoice_test.rb
|
91
|
+
- test/lib/invoice/version_test.rb
|
92
|
+
- test/test_helper.rb
|