payoneer_csv 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payoneer-csv.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec'
8
+ gem 'simplecov', require: false
9
+
10
+ gem 'awesome_print'
11
+ gem 'debugger'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Łukasz Bandzarewicz
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
+ # Payoneer::Csv
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'payoneer-csv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install payoneer-csv
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
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
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/payoneer_csv ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless ARGV[0]
4
+ puts 'Usage: payoneer_csv /path/to/transaction_list.pdf'
5
+ exit
6
+ end
7
+
8
+ payoneer_csv_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(payoneer_csv_dir) unless $LOAD_PATH.include?(payoneer_csv_dir)
10
+
11
+ require 'payoneer_csv'
12
+
13
+ file_path = File.expand_path(ARGV[0])
14
+ reader = PayoneerCsv::PdfReader.new(file_path)
15
+ csv_string = PayoneerCsv::Csv.new(reader.read).generate
16
+ puts csv_string
@@ -0,0 +1,28 @@
1
+ module PayoneerCsv
2
+
3
+ class Csv
4
+ attr_reader :transactions
5
+
6
+ def initialize(transactions)
7
+ @transactions = transactions
8
+ end
9
+
10
+ def generate
11
+ CSV.generate do |csv|
12
+ csv << ['Transaction Date', 'Description', 'Amount', 'Currency']
13
+
14
+ transactions.each do |transaction|
15
+ csv << row_for(transaction)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def row_for(transaction)
23
+ row = [:created_at, :description, :amount].map { |field| transaction.send(field) }
24
+ row << 'USD'
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,32 @@
1
+ module PayoneerCsv
2
+
3
+ class PdfReader
4
+ attr_reader :file_path
5
+
6
+ def initialize(file_path)
7
+ @file_path = file_path
8
+ end
9
+
10
+ def read
11
+ transactions = []
12
+
13
+ raw_data.each_line do |row|
14
+ match_data = parse(row)
15
+ next unless match_data
16
+
17
+ transactions << Transaction.new(match_data)
18
+ end
19
+
20
+ transactions
21
+ end
22
+
23
+ def raw_data
24
+ `less #{file_path}`
25
+ end
26
+
27
+ def parse(row)
28
+ row.match /^(?<created_at>\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d{2}:\d{2} (AM|PM))\s+ (?<description>.+) (?<amount>-?(\d|,)+\.\d{2})\s+USD$/
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,15 @@
1
+ module PayoneerCsv
2
+
3
+ class Transaction
4
+ attr_reader :description
5
+ attr_reader :amount
6
+ attr_reader :created_at
7
+
8
+ def initialize(attributes)
9
+ @created_at = attributes[:created_at]
10
+ @description = attributes[:description].strip
11
+ @amount = attributes[:amount].to_f
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ module PayoneerCsv
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'csv'
2
+
3
+ require 'payoneer_csv/version'
4
+ require 'payoneer_csv/transaction'
5
+ require 'payoneer_csv/pdf_reader'
6
+ require 'payoneer_csv/csv'
7
+
8
+ module PayoneerCsv
9
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/payoneer_csv/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Lukasz Bandzarewicz"]
6
+ gem.email = ["lucassus@gmail.com"]
7
+ gem.description = %q{Simple tool for converting payoneer pdf report to csv file}
8
+ gem.summary = %q{Convert payoneer pdf report to csv file}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "payoneer_csv"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = PayoneerCsv::VERSION
17
+ end
Binary file
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe PayoneerCsv::Csv do
4
+ let(:first_transaction) { mock(created_at: '10/11/2011', description: 'Foo', amount: 123.12) }
5
+ let(:second_transaction) { mock(created_at: '01/09/2012', description: 'Bar', amount: -9.99) }
6
+
7
+ let(:transactions) { [first_transaction, second_transaction] }
8
+ let(:csv) { described_class.new(transactions) }
9
+ subject { csv }
10
+
11
+ describe '#generate' do
12
+ it { should respond_to(:generate) }
13
+
14
+ describe 'result' do
15
+ let(:csv_string) { csv.generate }
16
+ subject { csv_string }
17
+
18
+ it { should be_an_instance_of(String) }
19
+
20
+ it 'should include all transactions' do
21
+ parsed = CSV.parse(csv_string)
22
+
23
+ parsed.should have(3).items
24
+
25
+ header = parsed[0]
26
+ header[0].should == 'Transaction Date'
27
+ header[1].should == 'Description'
28
+ header[2].should == 'Amount'
29
+ header[3].should == 'Currency'
30
+
31
+ first_row = parsed[1]
32
+ created_at, description, amount, currency = *first_row
33
+ created_at.should == '10/11/2011'
34
+ description.should == 'Foo'
35
+ amount.should == '123.12'
36
+ currency.should == 'USD'
37
+
38
+ second_row = parsed[2]
39
+ created_at, description, amount, currency = *second_row
40
+ created_at.should == '01/09/2012'
41
+ description.should == 'Bar'
42
+ amount.should == '-9.99'
43
+ currency.should == 'USD'
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe PayoneerCsv::PdfReader do
4
+ let(:file_path) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'Transactions.pdf') }
5
+
6
+ let(:reader) { described_class.new(file_path) }
7
+ subject { reader }
8
+
9
+ its(:file_path) { should == file_path }
10
+
11
+ describe 'raw_data' do
12
+ it { should respond_to(:raw_data) }
13
+
14
+ describe 'result' do
15
+ subject { reader.raw_data }
16
+
17
+ it 'should include some transactions' do
18
+ should_not be_empty
19
+
20
+ should include('10/19/2012 11:38:12 PM PSS SKLEP NR 54 -17.36 USD')
21
+ should include('10/19/2012 6:41:14 AM COSTA COFFEE -7.41 USD')
22
+ # ...
23
+ should include('10/15/2012 8:44:18 AM PKP Intercity -48.61 USD')
24
+ end
25
+ end
26
+ end
27
+
28
+ describe 'parse' do
29
+ it { should respond_to(:parse) }
30
+
31
+ describe 'result' do
32
+ subject { reader.parse(row) }
33
+
34
+ context 'on valid row (with negative amount)' do
35
+ let(:row) { '10/17/2012 5:58:20 AM ATM Withdrawal - Vaci u. 42. -75.29 USD' }
36
+
37
+ it { should_not be_nil }
38
+ its([:created_at]) { should == '10/17/2012 5:58:20 AM' }
39
+ its([:description]) { should == 'ATM Withdrawal - Vaci u. 42. ' }
40
+ its([:amount]) { should == '-75.29' }
41
+ end
42
+
43
+ context 'on valid row (with positive amount)' do
44
+ let(:row) { '10/19/2012 11:38:12 PM PSS SKLEP NR 54 17.36 USD' }
45
+
46
+ it { should_not be_nil }
47
+ its([:created_at]) { should == '10/19/2012 11:38:12 PM' }
48
+ its([:description]) { should == 'PSS SKLEP NR 54 ' }
49
+ its([:amount]) { should == '17.36' }
50
+ end
51
+
52
+ context 'on invalid row' do
53
+ let(:row) { 'invalid transaction data' }
54
+
55
+ it { should be_nil }
56
+ end
57
+ end
58
+ end
59
+
60
+ describe 'read' do
61
+ it { should respond_to(:read) }
62
+
63
+ describe 'result' do
64
+ let(:result) { reader.read }
65
+ subject { result }
66
+
67
+ it { should have(7).items }
68
+
69
+ describe 'first transaction' do
70
+ subject { result.first }
71
+
72
+ its(:created_at) { should == '10/19/2012 11:38:12 PM' }
73
+ its(:description) { should == 'PSS SKLEP NR 54' }
74
+ its(:amount) { should == -17.36 }
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PayoneerCsv::Transaction do
4
+ let(:attributes) {
5
+ {
6
+ description: 'Sample transaction',
7
+ amount: '123.99',
8
+ created_at: '10/19/2012 11:38:12 PM'
9
+ }
10
+ }
11
+
12
+ let(:transaction) { described_class.new(attributes) }
13
+ subject { transaction }
14
+
15
+ its(:description) { should == attributes[:description] }
16
+ its(:amount) { should == attributes[:amount].to_f }
17
+ its(:created_at) { should == attributes[:created_at] }
18
+
19
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
7
+ require 'payoneer_csv'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payoneer_csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lukasz Bandzarewicz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple tool for converting payoneer pdf report to csv file
15
+ email:
16
+ - lucassus@gmail.com
17
+ executables:
18
+ - payoneer_csv
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .rspec
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - bin/payoneer_csv
29
+ - lib/payoneer_csv.rb
30
+ - lib/payoneer_csv/csv.rb
31
+ - lib/payoneer_csv/pdf_reader.rb
32
+ - lib/payoneer_csv/transaction.rb
33
+ - lib/payoneer_csv/version.rb
34
+ - payoneer_csv.gemspec
35
+ - spec/fixtures/Transactions.pdf
36
+ - spec/payoneer_csv/csv_spec.rb
37
+ - spec/payoneer_csv/pdf_reader_spec.rb
38
+ - spec/payoneer_csv/transaction_spec.rb
39
+ - spec/spec_helper.rb
40
+ homepage: ''
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.24
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Convert payoneer pdf report to csv file
64
+ test_files:
65
+ - spec/fixtures/Transactions.pdf
66
+ - spec/payoneer_csv/csv_spec.rb
67
+ - spec/payoneer_csv/pdf_reader_spec.rb
68
+ - spec/payoneer_csv/transaction_spec.rb
69
+ - spec/spec_helper.rb
70
+ has_rdoc: