├── Gemfile ├── Rakefile ├── .gitmodules ├── bin ├── setup ├── console └── ci │ └── deploy ├── .gitignore ├── lib ├── zengin_code │ ├── branch.rb │ ├── version.rb │ └── bank.rb └── zengin_code.rb ├── .github └── workflows │ └── update.yml ├── README.md ├── LICENSE.txt └── zengin_code.gemspec /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | task default: :spec 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "source-data"] 2 | path = source-data 3 | url = https://github.com/zengin-code/source-data.git 4 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | /vendor 11 | /.ruby-version 12 | -------------------------------------------------------------------------------- /lib/zengin_code/branch.rb: -------------------------------------------------------------------------------- 1 | require 'zengin_code' 2 | 3 | class ZenginCode::Branch 4 | def initialize(bank, options = {}) 5 | @bank = bank 6 | @code = options['code'] 7 | @name = options['name'] 8 | @kana = options['kana'] 9 | @hira = options['hira'] 10 | @roma = options['roma'] 11 | end 12 | attr_reader :bank, :code, :name, :kana, :hira, :roma 13 | end 14 | -------------------------------------------------------------------------------- /lib/zengin_code/version.rb: -------------------------------------------------------------------------------- 1 | require 'pathname' 2 | 3 | module ZenginCode 4 | ROOT_DIR = Pathname.new(File.expand_path(__FILE__)).join('../../..') 5 | DATA_DIR = ROOT_DIR.join('source-data', 'data') 6 | GEM_VERSION = '1.0.1' 7 | 8 | def self.version 9 | "#{GEM_VERSION}-p#{File.read(DATA_DIR.join('updated_at')).strip}" 10 | end 11 | 12 | VERSION = version 13 | end 14 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "zengin_code" 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 15 | -------------------------------------------------------------------------------- /bin/ci/deploy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git config user.name "github-actions[bot]" 4 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" 5 | 6 | CI_RELEASE_VERSION=`date +"v%Y-%m-%d"` 7 | 8 | if [ -z "$(git status -s)" ]; then 9 | echo "No changes to commit" 10 | exit 0 11 | fi 12 | 13 | git commit -a -m "Update: ${CI_RELEASE_VERSION}" 14 | git push --all 15 | 16 | bundle exec rake release 17 | -------------------------------------------------------------------------------- /lib/zengin_code/bank.rb: -------------------------------------------------------------------------------- 1 | require 'zengin_code' 2 | 3 | class ZenginCode::Bank 4 | @banks = {} 5 | 6 | class << self 7 | def [](code) 8 | @banks[code] 9 | end 10 | 11 | def []=(code, bank) 12 | @banks[code] = bank 13 | end 14 | 15 | def all 16 | @banks 17 | end 18 | end 19 | 20 | def initialize(options = {}) 21 | @code = options['code'] 22 | @name = options['name'] 23 | @kana = options['kana'] 24 | @hira = options['hira'] 25 | @roma = options['roma'] 26 | @branches = {} 27 | self.class[code] = self 28 | end 29 | attr_reader :code, :name, :kana, :hira, :roma, :branches 30 | end 31 | -------------------------------------------------------------------------------- /lib/zengin_code.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'zengin_code/version' 3 | require 'zengin_code/bank' 4 | require 'zengin_code/branch' 5 | 6 | module ZenginCode 7 | class << self 8 | def preload! 9 | banks = JSON.load(File.read(DATA_DIR.join('banks.json'))) 10 | 11 | banks.values.each do |bank| 12 | ZenginCode::Bank.new(bank) 13 | end 14 | 15 | ZenginCode::Bank.all.each_pair do |code, bank| 16 | branches = JSON.load(File.read(DATA_DIR.join("branches/#{code}.json"))) 17 | 18 | branches.values.each do |branch| 19 | branch = ZenginCode::Branch.new(bank, branch) 20 | bank.branches[branch.code] = branch 21 | end 22 | end 23 | end 24 | end 25 | 26 | preload! 27 | end 28 | -------------------------------------------------------------------------------- /.github/workflows/update.yml: -------------------------------------------------------------------------------- 1 | name: update 2 | 3 | on: 4 | push: 5 | 6 | schedule: 7 | # Run at 12:00 JST 8 | - cron: '0 3 * * *' 9 | 10 | jobs: 11 | update: 12 | runs-on: ubuntu-latest 13 | 14 | permissions: 15 | contents: write 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | with: 20 | submodules: 'recursive' 21 | 22 | - uses: ruby/setup-ruby@v1 23 | with: 24 | ruby-version: 3.3 25 | bundler-cache: true 26 | 27 | - name: Checkout source-data 28 | run: | 29 | git submodule update --remote 30 | 31 | - name: Deploy 32 | if: github.ref == 'refs/heads/master' 33 | run: ./bin/ci/deploy 34 | env: 35 | GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZenginCode 2 | 3 | [![update](https://github.com/zengin-code/zengin-rb/actions/workflows/update.yml/badge.svg)](https://github.com/zengin-code/zengin-rb/actions/workflows/update.yml) 4 | [![Gem Version](https://badge.fury.io/rb/zengin_code.svg)](http://badge.fury.io/rb/zengin_code) 5 | 6 | The ruby implementation of ZenginCode. 7 | 8 | ZenginCode is datasets of bank codes and branch codes for japanese. 9 | 10 | ## Installation 11 | 12 | Add this line to your application's Gemfile: 13 | 14 | ```ruby 15 | gem 'zengin_code' 16 | ``` 17 | 18 | And then execute: 19 | 20 | $ bundle 21 | 22 | Or install it yourself as: 23 | 24 | $ gem install zengin_code 25 | 26 | ## Usage 27 | 28 | ```ruby 29 | require 'zengin_code' 30 | 31 | ZenginCode::Bank.all => { '00001' => <#ZenginCode::Bank code, name, kana, hira, roma ... >, .... } 32 | ``` 33 | 34 | ## Contributing 35 | 36 | Bug reports and pull requests are welcome on GitHub at https://github.com/zengin-code/zengin-rb 37 | 38 | 39 | ## License 40 | 41 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 42 | 43 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sho Kusano 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /zengin_code.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'zengin_code/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "zengin_code" 8 | spec.version = ZenginCode::VERSION.sub('-p', '.') 9 | spec.authors = ["Sho Kusano"] 10 | spec.email = ["rosylilly@aduca.org"] 11 | 12 | spec.summary = %q{bank codes and branch codes for japanese} 13 | spec.description = %q{bank codes and branch codes for japanese} 14 | spec.homepage = "https://github.com/zengin-code/zengin-rb" 15 | spec.license = "MIT" 16 | 17 | data_files = Dir['source-data/data/**/*.json'] 18 | data_files += %w(source-data/data/updated_at source-data/data/md5) 19 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 20 | spec.files += data_files 21 | spec.bindir = "exe" 22 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 23 | spec.require_paths = ["lib"] 24 | 25 | spec.add_development_dependency "bundler" 26 | spec.add_development_dependency "rake", ">= 12.3.3" 27 | end 28 | --------------------------------------------------------------------------------