ynab_tw 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a7208d7a3a208ee7c5a4d5260d318dd60170491
4
+ data.tar.gz: 6e1c9d8e0d6edbc712e5eee03548b9eafc9a7d41
5
+ SHA512:
6
+ metadata.gz: 9db45a3dd54b5b2235809260429892f0532d7ef1cffa891ce379f3674352b38be3262a017934130aca44009dae51ee8d07587398fa72d0e82f40f6ae8f1d7592
7
+ data.tar.gz: b285362a54a2bac233f955bddcfd045057e4abf5ecc9af0c10f89d409eb44c5b22b4c4e8fcacd1c9c286bddb2d0c5ef14f1e69933029ca01b0c36e3f89c6e612
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ynab_tw.gemspec
4
+ gemspec
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 John Lin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # YnabTw: Convert Taiwan banks's exported csv to YNAB's format
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'ynab_tw'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ynab_tw
18
+
19
+ ## Usage
20
+
21
+ ``` bash
22
+ $ bundle exec ynab_tw -b cathay withdraw.csv
23
+ 10/03/2016, 自行提款,, 00000000 , 5000,
24
+ ```
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/johnlinvc/ynab_tw.
35
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ynab_tw"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'ynab_tw'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ parser = OptionParser.new do |opts|
9
+ opts.banner = "Usage: ynab_tw -b mybank data.csv"
10
+
11
+ opts.on("-bBANK", "--bank=BANK", "Bank to convert from") do |b|
12
+ options[:bank] = b
13
+ end
14
+
15
+ opts.on("-h", "--help", "show this help") do |h|
16
+ puts opts
17
+ exit -1
18
+ end
19
+
20
+ end
21
+ parser.parse!
22
+
23
+ CONVERTERS = {
24
+ "cathay" => YnabTw::Cathay::Converter,
25
+ "cathay_credit" => YnabTw::Cathay::CreditConverter,
26
+ }
27
+
28
+ filename = ARGV[0]
29
+ bank = options[:bank]
30
+
31
+ def show_missing(name, arg, parser)
32
+ unless arg
33
+ puts "missing #{name}"
34
+ puts parser
35
+ exit -1
36
+ end
37
+ end
38
+
39
+ show_missing("csv", filename, parser)
40
+ show_missing("bank", bank, parser)
41
+
42
+ converter = CONVERTERS[bank].new
43
+ puts converter.convert(filename)
@@ -0,0 +1,6 @@
1
+ require "ynab_tw/version"
2
+ require "ynab_tw/cathay"
3
+
4
+ module YnabTw
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,2 @@
1
+ require "ynab_tw/cathay/converter"
2
+ require "ynab_tw/cathay/credit_converter"
@@ -0,0 +1,28 @@
1
+ require 'ynab_tw/converter'
2
+ module YnabTw::Cathay
3
+ class Converter
4
+ include YnabTw::Converter
5
+
6
+ def useless_header_count
7
+ 2
8
+ end
9
+
10
+ def input_headers
11
+ %w{date withdraw deposit balance info memo extra}
12
+ end
13
+
14
+ def convert_format(csv)
15
+ csv.each.map do |row|
16
+ [
17
+ DateTime.parse(row["date"]).strftime("%m/%d/%Y"),
18
+ row["info"],
19
+ nil,
20
+ "#{row["memo"]} #{row["extra"]}",
21
+ row["withdraw"],
22
+ row["deposit"],
23
+ ]
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ require 'ynab_tw/converter'
2
+ module YnabTw::Cathay
3
+ class CreditConverter
4
+ include YnabTw::Converter
5
+
6
+ def useless_header_count
7
+ 3
8
+ end
9
+
10
+ def input_headers
11
+ %w{date charge_date info withdraw card_no mobi_card_no country currency foreign_amount exchange_date}
12
+ end
13
+
14
+ def convert_format(csv)
15
+ valid_rows = csv.each.reject do |row|
16
+ row["date"].nil?
17
+ end
18
+ valid_rows.each.map do |row|
19
+ [
20
+ row["date"] + DateTime.now.strftime("/%Y"),
21
+ row["info"],
22
+ nil,
23
+ "card_no:#{row["card_no"]}",
24
+ row["withdraw"],
25
+ 0,
26
+ ]
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'csv'
2
+
3
+ module YnabTw
4
+ module Converter
5
+
6
+ def parse(filename)
7
+ csv = nil
8
+ File.open(filename, "r:big5:utf-8") do |f|
9
+ lines = f.each_line.to_a
10
+ ary = lines.drop(useless_header_count)
11
+ csv_str = ary.join("")
12
+ csv = ::CSV.parse(csv_str, headers: input_headers)
13
+ end
14
+ return csv
15
+ end
16
+
17
+ def convert(filename)
18
+ csv = parse(filename)
19
+ new_csv = convert_format(csv)
20
+ header = "Date,Payee,Category,Memo,Outflow,Inflow\n"
21
+ header + new_csv.map(&:to_csv).join("")
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module YnabTw
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ynab_tw/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ynab_tw"
8
+ spec.version = YnabTw::VERSION
9
+ spec.authors = ["johnlinvc"]
10
+ spec.email = ["johnlinvc@gmail.com"]
11
+
12
+ spec.summary = %q{Convert Taiwan bank export CSVs to YNAB CSV format}
13
+ spec.description = %q{Convert Taiwan bank export CSVs to YNAB CSV format }
14
+ spec.homepage = "http://github.com/johnlinvc/ynab_tw"
15
+ spec.licenses = ['MIT']
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
26
+ spec.add_development_dependency "pry-byebug", "~> 3.4"
27
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ynab_tw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - johnlinvc
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ description: 'Convert Taiwan bank export CSVs to YNAB CSV format '
84
+ email:
85
+ - johnlinvc@gmail.com
86
+ executables:
87
+ - ynab_tw
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Guardfile
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/ynab_tw
102
+ - lib/ynab_tw.rb
103
+ - lib/ynab_tw/cathay.rb
104
+ - lib/ynab_tw/cathay/converter.rb
105
+ - lib/ynab_tw/cathay/credit_converter.rb
106
+ - lib/ynab_tw/converter.rb
107
+ - lib/ynab_tw/version.rb
108
+ - ynab_tw.gemspec
109
+ homepage: http://github.com/johnlinvc/ynab_tw
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Convert Taiwan bank export CSVs to YNAB CSV format
133
+ test_files: []