ubimport 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.md +25 -0
- data/README.rdoc +19 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/bin/ubimport +6 -0
- data/lib/ub_importer.rb +35 -0
- data/lib/ubimport.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/ub_importer_spec.rb +38 -0
- data/ubimport.gemspec +69 -0
- metadata +157 -0
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'fastercsv'
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.3.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.5.2"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
fastercsv (1.5.4)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rake (0.8.7)
|
12
|
+
rcov (0.9.9)
|
13
|
+
rspec (2.3.0)
|
14
|
+
rspec-core (~> 2.3.0)
|
15
|
+
rspec-expectations (~> 2.3.0)
|
16
|
+
rspec-mocks (~> 2.3.0)
|
17
|
+
rspec-core (2.3.1)
|
18
|
+
rspec-expectations (2.3.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.3.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
bundler (~> 1.0.0)
|
27
|
+
fastercsv
|
28
|
+
jeweler (~> 1.5.2)
|
29
|
+
rcov
|
30
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Paul Campbell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# UBImporter #
|
2
|
+
|
3
|
+
An import utility for Ulster Bank Ireland Bankline CSV files that outputs a CSV file compatible with Xero.com
|
4
|
+
|
5
|
+
## Install ##
|
6
|
+
|
7
|
+
gem install ubimport
|
8
|
+
|
9
|
+
## Usage ##
|
10
|
+
|
11
|
+
ubimport path-to-csv-file.csv
|
12
|
+
|
13
|
+
if you want to create a new file
|
14
|
+
|
15
|
+
ubimport path-to-csv-file.csv > new-file.csv
|
16
|
+
|
17
|
+
## API ##
|
18
|
+
|
19
|
+
require 'ubimporter'
|
20
|
+
|
21
|
+
infile = '/path/to/csv_file.csv'
|
22
|
+
outfile = '/path/to/csv_file_fixed.csv'
|
23
|
+
|
24
|
+
importer = UBImporter.new(file)
|
25
|
+
importer.write(outfile)
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= ubimport
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to ubimport
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
PKG_FILES = FileList[
|
13
|
+
'[a-zA-Z]*',
|
14
|
+
'bin/**/*',
|
15
|
+
'lib/**/*',
|
16
|
+
]
|
17
|
+
|
18
|
+
require 'jeweler'
|
19
|
+
Jeweler::Tasks.new do |gem|
|
20
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
21
|
+
gem.name = "ubimport"
|
22
|
+
gem.homepage = "http://github.com/paulca/ubimport"
|
23
|
+
gem.license = "MIT"
|
24
|
+
gem.summary = %Q{Convert Ulster Bank Ireland Bankline CSV files into a format compatible with Xero.com}
|
25
|
+
gem.description = %Q{A useful tool until Xero.com supports Ulster Bank Ireland}
|
26
|
+
gem.email = "paul@rslw.com"
|
27
|
+
gem.authors = ["Paul Campbell"]
|
28
|
+
gem.files = PKG_FILES.to_a
|
29
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
30
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
31
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
32
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
33
|
+
end
|
34
|
+
Jeweler::RubygemsDotOrgTasks.new
|
35
|
+
|
36
|
+
require 'rspec/core'
|
37
|
+
require 'rspec/core/rake_task'
|
38
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
39
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
43
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
44
|
+
spec.rcov = true
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "ubimport #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/ubimport
ADDED
data/lib/ub_importer.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fastercsv'
|
2
|
+
class UBImporter
|
3
|
+
|
4
|
+
attr_accessor :original_file, :original_lines, :changed_lines
|
5
|
+
|
6
|
+
def initialize(original_file)
|
7
|
+
@original_file = original_file
|
8
|
+
@original_lines = []
|
9
|
+
@changed_lines = []
|
10
|
+
FasterCSV.foreach(original_file) do |row|
|
11
|
+
@original_lines << row
|
12
|
+
end
|
13
|
+
@original_lines.each do |line|
|
14
|
+
@changed_lines << process_line(line)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def output
|
19
|
+
changed_lines.collect { |line| line.to_csv }.join
|
20
|
+
end
|
21
|
+
|
22
|
+
def process_line(line)
|
23
|
+
if line.first == 'Sort Code'
|
24
|
+
line[17] = 'Amount'
|
25
|
+
line[16] = 'TxType'
|
26
|
+
elsif line.last.to_i > 0
|
27
|
+
line[16] = 'CREDIT'
|
28
|
+
elsif line[16].to_i < 0
|
29
|
+
line[17] = line[16]
|
30
|
+
line[16] = 'DEBIT'
|
31
|
+
end
|
32
|
+
line
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/ubimport.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ub_importer'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'lib/ub_importer'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UBImporter do
|
4
|
+
|
5
|
+
let(:importer) { UBImporter.new('spec/fixtures/sample.csv') }
|
6
|
+
|
7
|
+
describe "#original_lines" do
|
8
|
+
it "should load the file" do
|
9
|
+
importer.should have(3).original_lines
|
10
|
+
importer.should have(3).changed_lines
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should change the last few parts of the first line" do
|
14
|
+
importer.changed_lines.first.length.should == 18
|
15
|
+
importer.changed_lines.first[17].should == 'Amount'
|
16
|
+
importer.changed_lines.first[16].should == 'TxType'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should change the last few parts of the second line" do
|
20
|
+
importer.changed_lines[1].length.should == 18
|
21
|
+
importer.changed_lines[1][17].should == '-900.00'
|
22
|
+
importer.changed_lines[1][16].should == 'DEBIT'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should change the last few parts of the third line" do
|
26
|
+
importer.changed_lines[2].length.should == 18
|
27
|
+
importer.changed_lines[2][17].should == '3811.50'
|
28
|
+
importer.changed_lines[2][16].should == 'CREDIT'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#output" do
|
33
|
+
it "should output the file correctly" do
|
34
|
+
importer.output.should == File.read('spec/fixtures/sample_output.csv')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/ubimport.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ubimport}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Paul Campbell"]
|
12
|
+
s.date = %q{2011-02-05}
|
13
|
+
s.default_executable = %q{ubimport}
|
14
|
+
s.description = %q{A useful tool until Xero.com supports Ulster Bank Ireland}
|
15
|
+
s.email = %q{paul@rslw.com}
|
16
|
+
s.executables = ["ubimport"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md",
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"bin/ubimport",
|
31
|
+
"lib/ub_importer.rb",
|
32
|
+
"lib/ubimport.rb",
|
33
|
+
"ubimport.gemspec"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/paulca/ubimport}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.4.2}
|
39
|
+
s.summary = %q{Convert Ulster Bank Ireland Bankline CSV files into a format compatible with Xero.com}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/ub_importer_spec.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
53
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ubimport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Paul Campbell
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-05 00:00:00 +00:00
|
19
|
+
default_executable: ubimport
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
name: fastercsv
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
name: rspec
|
38
|
+
type: :development
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
version: 2.3.0
|
50
|
+
requirement: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
prerelease: false
|
53
|
+
name: bundler
|
54
|
+
type: :development
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 0
|
64
|
+
- 0
|
65
|
+
version: 1.0.0
|
66
|
+
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
prerelease: false
|
69
|
+
name: jeweler
|
70
|
+
type: :development
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 7
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 5
|
80
|
+
- 2
|
81
|
+
version: 1.5.2
|
82
|
+
requirement: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
prerelease: false
|
85
|
+
name: rcov
|
86
|
+
type: :development
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirement: *id005
|
97
|
+
description: A useful tool until Xero.com supports Ulster Bank Ireland
|
98
|
+
email: paul@rslw.com
|
99
|
+
executables:
|
100
|
+
- ubimport
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- README.rdoc
|
107
|
+
files:
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- README.rdoc
|
113
|
+
- Rakefile
|
114
|
+
- VERSION
|
115
|
+
- bin/ubimport
|
116
|
+
- lib/ub_importer.rb
|
117
|
+
- lib/ubimport.rb
|
118
|
+
- ubimport.gemspec
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
- spec/ub_importer_spec.rb
|
121
|
+
has_rdoc: true
|
122
|
+
homepage: http://github.com/paulca/ubimport
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 3
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
hash: 3
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
requirements: []
|
149
|
+
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.4.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Convert Ulster Bank Ireland Bankline CSV files into a format compatible with Xero.com
|
155
|
+
test_files:
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
- spec/ub_importer_spec.rb
|