rosetta_coin 0.0.1

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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rosetta_coin.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dennis de Reus
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,44 @@
1
+ # RosettaCoin
2
+
3
+ RosettaCoin is an extensible system to convert between various banking export formats. Currently only Rabobank CSV and ledger are supported, and I encourage you to fork the gem and add more modules for conversion of any format you need
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rosetta_coin'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rosetta_coin
18
+
19
+ ## Usage
20
+
21
+ ````ruby
22
+ require 'rosetta_coin'
23
+
24
+ converter = RosettaCoin.new(
25
+ input_format: 'rabobank_csv',
26
+ output_format: 'ledger')
27
+
28
+ input_file = File.new("readfile.csv", "r")
29
+ output_file = File.new("writefile.txt", "w")
30
+
31
+ while line = input_file.gets
32
+ output_file.puts converter.convert(line)
33
+ end
34
+
35
+ output_file.close
36
+ ````
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ require "rosetta_coin/version"
2
+ require "rosetta_coin/transaction"
3
+ require "rosetta_coin/input_format"
4
+ require "rosetta_coin/output_format"
5
+
6
+ class RosettaCoin
7
+ attr_accessor :input_format, :output_format
8
+
9
+ def initialize(options)
10
+ @input_format = options[:input_format]
11
+ @output_format = options[:output_format]
12
+ @input_formatter = RosettaCoin::InputFormat.const_get(@input_format)
13
+ @output_formatter = RosettaCoin::OutputFormat.const_get(@output_format) if @output_format
14
+ end
15
+
16
+ def convert(text, options = {})
17
+ transaction = Transaction.new(@input_formatter.convert(text, options[:input_formatter_options]))
18
+ if @output_formatter
19
+ return @output_formatter.convert(transaction, options[:output_formatter_options])
20
+ else
21
+ return transaction
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ require "rosetta_coin/input_format/rabobank_csv"
2
+
3
+ class RosettaCoin::InputFormat
4
+ end
@@ -0,0 +1,22 @@
1
+ require 'CSV'
2
+
3
+ class RosettaCoin
4
+ class InputFormat
5
+ class RabobankCsv
6
+ def self.convert(text, options = {})
7
+ result = {}
8
+ CSV.parse(text) do |row|
9
+ result[:date] = Date.parse(row[2])
10
+ result[:account_number] = row[0]
11
+ result[:currency] = row[1]
12
+ result[:amount] = (row[3]=="D" ? -1.0 * row[4].to_f : row[4].to_f)
13
+ result[:description] = (row[10] + ", " + row[11] + ", " + row[12] + ", " + row [13]).gsub(/(, ?)*$/,"")
14
+ result[:type] = row[8]
15
+ result[:counter_party_name] = row[6]
16
+ result[:counter_party_account_number] = row[5]
17
+ end
18
+ return result
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ require "rosetta_coin/output_format/ledger"
2
+
3
+ class RosettaCoin::OutputFormat
4
+ end
@@ -0,0 +1,14 @@
1
+ class RosettaCoin
2
+ class OutputFormat
3
+ class Ledger
4
+ def self.convert(transaction, options = nil)
5
+ # TODO: clean up
6
+ return "#{transaction.year}/#{transaction.month}/#{transaction.day} #{transaction.counter_party_name}-#{transaction.counter_party_account_number}\n"+
7
+ " ;#{transaction.description}\n"+
8
+ " Assets:" + ((options && options[:account_descriptions] && options[:account_descriptions].keys.include?(transaction.account_number)) ? options[:account_descriptions][transaction.account_number] : transaction.account_number) +
9
+ "\t\t #{transaction.currency} #{transaction.amount.to_f}\n" +
10
+ " " + (transaction.amount < 0 ? "Expenses:Uncategorized" : "Income:Uncategorized") + "\n"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ class RosettaCoin
2
+ class Transaction
3
+
4
+ attr_accessor :date, :account_number, :currency, :amount, :description, :type, :counter_party_name, :counter_party_account_number
5
+
6
+ def initialize(data)
7
+ data.each do |k, v|
8
+ public_send("#{k.to_s}=", v)
9
+ end
10
+ end
11
+
12
+ def year
13
+ self.date.year
14
+ end
15
+
16
+ def month
17
+ self.date.month
18
+ end
19
+
20
+ def day
21
+ self.date.day
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ class RosettaCoin
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rosetta_coin/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rosetta_coin"
8
+ gem.version = RosettaCoin::VERSION
9
+ gem.authors = ["Dennis de Reus"]
10
+ gem.email = ["dennisdereus@gmail.com"]
11
+ gem.description = %q{Converts exported bank transactions to various formats}
12
+ gem.summary = %q{Bank transaction conversion tool}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rosetta_coin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dennis de Reus
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Converts exported bank transactions to various formats
15
+ email:
16
+ - dennisdereus@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/rosetta_coin.rb
27
+ - lib/rosetta_coin/input_format.rb
28
+ - lib/rosetta_coin/input_format/rabobank_csv.rb
29
+ - lib/rosetta_coin/output_format.rb
30
+ - lib/rosetta_coin/output_format/ledger.rb
31
+ - lib/rosetta_coin/transaction.rb
32
+ - lib/rosetta_coin/version.rb
33
+ - rosetta_coin.gemspec
34
+ homepage: ''
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.8.24
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Bank transaction conversion tool
58
+ test_files: []