-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 01d6dc1
Showing
20 changed files
with
543 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.gem | ||
*.rbc | ||
|
||
.bundle | ||
|
||
doc | ||
coverage | ||
vendor/bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: ruby | ||
bundler_args: --without development | ||
script: bundle exec rspec spec | ||
rvm: | ||
- 1.9.2 | ||
- 1.9.3 | ||
- 2.0.0 | ||
- jruby-19mode | ||
- rbx-19mode | ||
branches: | ||
only: master | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
source 'https://rubygems.org' | ||
|
||
group :development, :test do | ||
gem 'pry' | ||
end | ||
|
||
group :test do | ||
gem 'rspec' | ||
gem 'simplecov', require: false | ||
end | ||
|
||
group :doc do | ||
gem 'sdoc' | ||
end | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
zengin (0.1.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
coderay (1.0.9) | ||
diff-lcs (1.2.4) | ||
json (1.8.0) | ||
method_source (0.8.2) | ||
multi_json (1.7.9) | ||
pry (0.9.12.2) | ||
coderay (~> 1.0.5) | ||
method_source (~> 0.8) | ||
slop (~> 3.4) | ||
rdoc (3.12.2) | ||
json (~> 1.4) | ||
rspec (2.14.1) | ||
rspec-core (~> 2.14.0) | ||
rspec-expectations (~> 2.14.0) | ||
rspec-mocks (~> 2.14.0) | ||
rspec-core (2.14.4) | ||
rspec-expectations (2.14.1) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-mocks (2.14.3) | ||
sdoc (0.3.20) | ||
json (>= 1.1.3) | ||
rdoc (~> 3.10) | ||
simplecov (0.7.1) | ||
multi_json (~> 1.0) | ||
simplecov-html (~> 0.7.1) | ||
simplecov-html (0.7.1) | ||
slop (3.4.6) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
pry | ||
rspec | ||
sdoc | ||
simplecov | ||
zengin! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2013 Shouichi Kamiya | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
### 全銀CSVエクスポーター | ||
|
||
全銀の形式のCSVを吐きます。 ネット銀行などを使って振込を自動で行いたい時に使っ | ||
て下さい。 | ||
|
||
### 使い方 | ||
|
||
``` | ||
# 振込先の配列 | ||
deposits = [ | ||
{ | ||
bank_code: 33, | ||
branch_code: 1, | ||
account_type: Zengin::AccountType.ordinary, | ||
account_number: 0123456, | ||
account_name: 'タロウ', | ||
amount: 888, | ||
}, | ||
{ | ||
bank_code: 5, | ||
branch_code: 1, | ||
account_type: Zengin::AccountType.current, | ||
account_number: 1234567, | ||
account_name: 'ジロウ', | ||
amount: 2525, | ||
}, | ||
] | ||
# 振込元(自分)の口座などを設定 | ||
exporter = Zengin::Exporter.new( | ||
client_name: 'ハナコ', | ||
client_branch_code: 1, | ||
client_account_number: 2345678, | ||
deposit_at: Time.now, | ||
deposits: deposits, | ||
) | ||
# CSVとして保存 | ||
exporter.export('/tmp/deposits.csv') | ||
``` | ||
|
||
### 開発 | ||
|
||
``` | ||
% bundle install | ||
% bundle exec rspec | ||
% bundle exec gem build zengin.gemspec | ||
% bundle exec gem install zengin-0.1.0.gem | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'csv' | ||
|
||
module Zengin | ||
end | ||
|
||
require 'zengin/errors' | ||
require 'zengin/formatters' | ||
require 'zengin/account_type' | ||
require 'zengin/exporter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Zengin | ||
module AccountType | ||
extend self | ||
|
||
def ordinary | ||
1 | ||
end | ||
|
||
def current | ||
2 | ||
end | ||
|
||
def saving | ||
4 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Zengin | ||
class Deposit | ||
attr_accessor :bank_code, :branch_code :account_type, :account_number, :account_name, :amount | ||
|
||
def initialize(options = {}) | ||
bank_code = options[:bank_code] | ||
branch_code = options[:branch_code] | ||
account_type = options[:account_type] | ||
account_number = options[:account_number] | ||
account_name = options[:account_name] | ||
amount = options[:amount] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Zengin | ||
class Error < StandardError | ||
end | ||
|
||
class RequiredArgumentMissingError < Error | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Zengin | ||
class Exporter | ||
attr_accessor :client_name, :client_branch_code, :client_account_number, :deposit_at, :deposits | ||
|
||
def initialize(options = {}) | ||
options = default_options.merge!(options) | ||
|
||
self.client_name = options[:client_name] | ||
self.client_branch_code = options[:client_branch_code] | ||
self.client_account_number = options[:client_account_number] | ||
self.deposit_at = options[:deposit_at] | ||
self.deposits = options[:deposits] | ||
end | ||
|
||
def rows | ||
deposits.reduce([build_header]) do |accumulator, deposit| | ||
accumulator << build_row(deposit) | ||
end | ||
end | ||
|
||
def export(path) | ||
CSV.open(path, 'wb', encoding: 'Shift_JIS') do |csv| | ||
rows.each do |row| | ||
csv << row | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def build_header | ||
Zengin::HeaderFormatter.new( | ||
client_name: client_name, | ||
client_branch_code: client_branch_code, | ||
client_account_number: client_account_number, | ||
deposit_at: deposit_at, | ||
).format | ||
end | ||
|
||
def build_row(deposit) | ||
Zengin::RowFormatter.new(deposit).format | ||
end | ||
|
||
def default_options | ||
default_options = { | ||
deposit_at: Time.now, | ||
deposits: [], | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Zengin | ||
class HeaderFormatter | ||
attr_accessor :client_name, :client_branch_code, :client_account_number, :deposit_at | ||
|
||
def initialize(options = {}) | ||
self.client_name = options[:client_name] | ||
self.client_branch_code = options[:client_branch_code] | ||
self.client_account_number = options[:client_account_number] | ||
self.deposit_at = options[:deposit_at] | ||
end | ||
|
||
def format | ||
[1, 21, 0, nil, client_name, formatted_deposit_at, 33, nil, client_branch_code, nil, 1, client_account_number] | ||
end | ||
|
||
private | ||
|
||
def formatted_deposit_at | ||
'%02d%02d' % [deposit_at.month, deposit_at.day] | ||
end | ||
end | ||
|
||
class RowFormatter | ||
attr_accessor :deposit | ||
|
||
def initialize(deposit) | ||
self.deposit = deposit | ||
end | ||
|
||
def format | ||
[2, deposit[:bank_code], nil, deposit[:branch_code], nil, nil, deposit[:account_type], deposit[:account_number], deposit[:account_name], deposit[:amount], 0, nil] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Zengin | ||
VERSION = '0.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
describe Zengin::AccountType do | ||
subject { Zengin::AccountType } | ||
|
||
describe '::ordinary' do | ||
it 'returns 1' do | ||
expect(subject.ordinary).to eq(1) | ||
end | ||
end | ||
|
||
describe '::current' do | ||
it 'returns 1' do | ||
expect(subject.current).to eq(2) | ||
end | ||
end | ||
|
||
describe '::saving' do | ||
it 'returns 1' do | ||
expect(subject.saving).to eq(4) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
describe Zengin::Exporter do | ||
let(:client_name) { 'sengoku38' } | ||
let(:client_branch_code) { 5 } | ||
let(:client_account_number) { 1234567 } | ||
let(:deposit_at) { Time.now } | ||
|
||
let(:deposits) do | ||
[ | ||
{ | ||
bank_code: 33, | ||
branch_code: 1, | ||
account_type: Zengin::AccountType.ordinary, | ||
account_number: 0123456, | ||
account_name: 'tarou', | ||
amount: 888, | ||
}, | ||
{ | ||
bank_code: 5, | ||
branch_code: 1, | ||
account_type: Zengin::AccountType.current, | ||
account_number: 1234567, | ||
account_name: 'jirou', | ||
amount: 2525, | ||
} | ||
] | ||
end | ||
|
||
let(:exporter) do | ||
Zengin::Exporter.new( | ||
client_name: client_name, | ||
client_branch_code: client_branch_code, | ||
client_account_number: client_account_number, | ||
deposit_at: deposit_at, | ||
deposits: deposits, | ||
) | ||
end | ||
|
||
describe '#rows' do | ||
subject { exporter.rows } | ||
|
||
it 'contains 1 + N(deposits) rows' do | ||
expect(subject).to have(3).items | ||
end | ||
end | ||
end |
Oops, something went wrong.