kirico 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11278a08f4962c88c18f859a5cf9daddc36aab19
4
+ data.tar.gz: 84a22bef5d2bd17da7e46795fae2519fe9202426
5
+ SHA512:
6
+ metadata.gz: 9a62c56c52fe852eb286108e56b7b7243e973381f0313bbf51a74457e649c7f214023cfb3e1d025ba84ba623ab4984599a7802fd5c292685e91a3a6d24ca45a7
7
+ data.tar.gz: dc24d98d2e5e99b4fe6b93518139c7e760b8793505e9875cff5f29b7458d10f652d215d70aee9f1ed62b259c31e57df05c4067a58037a70da70e2f41e4865dce
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,41 @@
1
+ inherit_from: '.rubocop_todo.yml'
2
+
3
+ Style/AsciiComments:
4
+ Enabled: false
5
+
6
+ Style/BlockDelimiters:
7
+ Enabled: false
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Style/DoubleNegation:
13
+ Enabled: false
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: true
17
+
18
+ Style/MutableConstant:
19
+ Enabled: false
20
+
21
+ Metrics/AbcSize:
22
+ Max: 50
23
+
24
+ Metrics/BlockLength:
25
+ Enabled: false
26
+
27
+ Metrics/ClassLength:
28
+ Max: 200
29
+
30
+ Metrics/CyclomaticComplexity:
31
+ Exclude:
32
+ - lib/kirico/csv_generator.rb
33
+ - lib/kirico/validators/sjis_bytesize_validator.rb
34
+
35
+ Metrics/LineLength:
36
+ Max: 200
37
+ Exclude:
38
+ - 'kirico.gemspec'
39
+
40
+ Metrics/MethodLength:
41
+ Max: 30
@@ -0,0 +1,47 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-12-23 20:27:11 +0900 using RuboCop version 0.46.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ Style/Documentation:
10
+ Exclude:
11
+ - 'spec/**/*'
12
+ - 'test/**/*'
13
+ - 'lib/kirico.rb'
14
+
15
+ # Offense count: 9
16
+ # Cop supports --auto-correct.
17
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
18
+ # SupportedStyles: when_needed, always
19
+ Style/FrozenStringLiteralComment:
20
+ Exclude:
21
+ - 'Gemfile'
22
+ - 'Guardfile'
23
+ - 'Rakefile'
24
+ - 'bin/console'
25
+ - 'kirico.gemspec'
26
+
27
+ # Offense count: 1
28
+ # Configuration parameters: MinBodyLength.
29
+ Style/GuardClause:
30
+ Exclude:
31
+ - 'kirico.gemspec'
32
+
33
+ # Offense count: 1
34
+ # Cop supports --auto-correct.
35
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
36
+ # SupportedStyles: only_raise, only_fail, semantic
37
+ Style/SignalException:
38
+ Exclude:
39
+ - 'kirico.gemspec'
40
+
41
+ # Offense count: 1
42
+ # Cop supports --auto-correct.
43
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
44
+ # SupportedStyles: single_quotes, double_quotes
45
+ Style/StringLiterals:
46
+ Exclude:
47
+ - 'kirico.gemspec'
@@ -0,0 +1 @@
1
+ 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kirico.gemspec
4
+ gemspec
@@ -0,0 +1,15 @@
1
+ guard :rspec, cmd: 'bundle exec rspec', failed_mode: :focus do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch(%r{^spec/factories/(.+)\.rb$}) { |m| "spec/kirico/models/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { 'spec' }
6
+ end
7
+
8
+ guard :bundler do
9
+ watch('Gemfile')
10
+ watch(/^.+\.gemspec/)
11
+ end
12
+
13
+ guard :rubocop, all_on_start: true, cli: ['-D', '--format', 'clang'] do
14
+ watch(/.+\.rb$/)
15
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 kakipo
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.
@@ -0,0 +1,45 @@
1
+ <img width="446" alt="kirico-logo" src="https://cloud.githubusercontent.com/assets/2214179/22500174/267fa8a8-e8a6-11e6-905f-fc79a049afab.png">
2
+
3
+ # Kirico
4
+
5
+ [![CircleCI](https://circleci.com/gh/kufu/kirico.svg?style=svg)](https://circleci.com/gh/kufu/kirico)
6
+
7
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kirico`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+
9
+ TODO: Delete this and the text above, and describe your gem
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'kirico'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install kirico
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kirico.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
@@ -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 'kirico'
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ machine:
2
+ timezone:
3
+ Asia/Tokyo
4
+
5
+ test:
6
+ pre:
7
+ - bundle exec rubocop --display-cop-names
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kirico/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kirico'
8
+ spec.version = Kirico::VERSION
9
+ spec.authors = ['kakipo']
10
+ spec.email = ['kakipo@gmail.com']
11
+
12
+ spec.summary = 'Write a short summary, because Rubygems requires one.'
13
+ spec.description = 'Write a longer description or delete this line.'
14
+ spec.homepage = 'https://github.com/kufu/kirico'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.required_ruby_version = '>= 2.3.1'
31
+
32
+ spec.add_dependency 'activesupport'
33
+ spec.add_dependency 'activemodel'
34
+ spec.add_dependency 'era_ja'
35
+ spec.add_dependency 'validates_timeliness'
36
+ spec.add_dependency 'virtus'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 1.10'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec'
41
+ spec.add_development_dependency 'factory_girl'
42
+ spec.add_development_dependency 'guard'
43
+ spec.add_development_dependency 'guard-rspec'
44
+ spec.add_development_dependency 'guard-bundler'
45
+ spec.add_development_dependency 'guard-rubocop'
46
+ spec.add_development_dependency 'pry'
47
+ spec.add_development_dependency 'pry-byebug'
48
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require 'kirico/version'
3
+ require 'kirico/models/changing_address_record'
4
+ require 'kirico/models/company_count'
5
+ require 'kirico/models/company_identifier'
6
+ require 'kirico/models/company'
7
+ require 'kirico/models/data_identifier'
8
+ require 'kirico/models/fd_management_record'
9
+ require 'kirico/models/helper'
10
+ require 'kirico/csv_generator'
11
+
12
+ module Kirico
13
+ locale_path = Dir.glob("#{File.dirname(__FILE__)}/kirico/config/locales/*.yml")
14
+ I18n.load_path += locale_path unless I18n.load_path.include?(locale_path)
15
+ end
@@ -0,0 +1,12 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ invalid_charset: "has invalid character(s): %{error_chars}"
5
+ invalid_date: "is not a valid date"
6
+ invalid_time: "is not a valid time"
7
+ invalid_datetime: "is not a valid datetime"
8
+ is_at: "must be at %{restriction}"
9
+ before: "must be before %{restriction}"
10
+ on_or_before: "must be on or before %{restriction}"
11
+ after: "must be after %{restriction}"
12
+ on_or_after: "must be on or after %{restriction}"
@@ -0,0 +1,59 @@
1
+ ja:
2
+ errors:
3
+ messages:
4
+ invalid_charset: "に利用できない文字が入力されています。%{error_chars}"
5
+ too_long: は%{count}文字以内で入力してください。
6
+ too_short: は%{count}文字以上で入力してください。
7
+ wrong_length: は%{count}文字で入力してください。
8
+ invalid_date: "は正しい形式で入力してください。"
9
+ invalid_time: "は正しい形式で入力してください。"
10
+ invalid_datetime: "は正しい形式で入力してください。"
11
+ is_at: "は %{restriction} である必要があります。"
12
+ before: "は %{restriction} より前を指定してください。"
13
+ on_or_before: "は %{restriction} 以前を指定してください。"
14
+ after: "は %{restriction} より後を指定してください。"
15
+ on_or_after: "は %{restriction} 以降を指定してください。"
16
+ activemodel:
17
+ models:
18
+ kirico/changing_address_record: 住所変更データレコード
19
+ kirico/company_count: 事業所数情報
20
+ kirico/company_identifier: 事業所識別符号
21
+ kirico/company: 事業所情報
22
+ kirico/data_identifier: データ識別符号
23
+ kirico/fd_management_record: FD管理レコード
24
+ attributes:
25
+ kirico/changing_address_record:
26
+ area_code: 都市区符号
27
+ office_code: 事業所記号
28
+ ip_code: 被保険者整理番号
29
+ basic_pension_number1: 基礎年金番号(課所符号)
30
+ basic_pension_number2: 基礎年金番号(一連番号)
31
+ birth_at: 生年月日
32
+ zip_code1: 郵便番号(親番号)
33
+ zip_code2: 郵便番号(子番号)
34
+ new_address_yomi: 変更後被保険者住所(カナ)
35
+ new_address: 変更後被保険者住所(漢字)
36
+ updated_at: 変更年月日
37
+ ip_name_yomi: 被保険者氏名(カナ)
38
+ ip_name: 被保険者氏名(漢字)
39
+ old_address_yomi: 変更前被保険者住所(カナ)
40
+ old_address: 変更前被保険者住所(漢字)
41
+ memo: 備考欄
42
+ kirico/company:
43
+ sr_name: 社会保険労務士氏名
44
+ count: 事業所数情報
45
+ area_code: 都市区符号
46
+ office_code: 事業所記号
47
+ office_number: 事業所番号
48
+ zip_code1: 郵便番号.親番号
49
+ zip_code2: 郵便番号.子番号
50
+ address: 事業所所在地
51
+ name: 事業所名称
52
+ owner_name: 事業主氏名
53
+ tel_number: 電話番号
54
+ kirico/fd_management_record:
55
+ area_code: 都市区符号
56
+ office_code: 事業所記号
57
+ fd_seq_number: FD通番
58
+ created_at: 作成年月日
59
+ main_doc_code: 代表届書コード
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module Kirico
3
+ class CSVGenerator
4
+ def initialize(fd_management_record, company, data = [])
5
+ @fd_management_record = fd_management_record
6
+ @company_identifier = CompanyIdentifier.new
7
+ @company_count = CompanyCount.new
8
+ @company = company
9
+ @data_identifier = DataIdentifier.new
10
+ @data = data
11
+ end
12
+
13
+ # 1 件: FD 管理レコード
14
+ # 1 件: 事業所識別符号
15
+ # 1 件: 事業所数情報
16
+ # 1 件: データ識別符号
17
+ # n 件: データレコード
18
+ def generate
19
+ [
20
+ @fd_management_record,
21
+ @company_identifier,
22
+ @company_count,
23
+ @company,
24
+ @data_identifier,
25
+ @data
26
+ ].flatten.map(&:to_csv).join("\n")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+ require 'virtus'
3
+ require 'active_model'
4
+ require 'kirico/models/helper'
5
+ require 'validates_timeliness'
6
+
7
+ module Kirico
8
+ class ChangingAddressRecord
9
+ include Virtus.model
10
+ include ActiveModel::Validations
11
+ extend Kirico::Helper
12
+
13
+ DOC_CODE = '22187041'
14
+
15
+ attribute :area_code, String
16
+ attribute :office_code, String
17
+ attribute :ip_code, String
18
+ attribute :basic_pension_number1, String
19
+ attribute :basic_pension_number2, String
20
+ attribute :birth_at, Date
21
+ attribute :zip_code1, String
22
+ attribute :zip_code2, String
23
+ attribute :new_address_yomi, String
24
+ attribute :new_address, String
25
+ attribute :updated_at, Date
26
+ attribute :ip_name_yomi, String
27
+ attribute :ip_name, String
28
+ attribute :old_address_yomi, String
29
+ attribute :old_address, String
30
+ attribute :memo, String
31
+
32
+ validates :area_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
33
+ validates :office_code, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..4 }
34
+ validates :ip_code, charset: { accept: [:numeric] }, sjis_bytesize: { in: 1..6 }
35
+ validates :basic_pension_number1, charset: { accept: [:numeric] }, sjis_bytesize: { is: 4 }, allow_blank: true
36
+ validates :basic_pension_number2, charset: { accept: [:numeric] }, sjis_bytesize: { is: 6 }, allow_blank: true
37
+ validates :zip_code1, charset: { accept: [:numeric] }, sjis_bytesize: { is: 3 }
38
+ validates :zip_code2, charset: { accept: [:numeric] }, sjis_bytesize: { is: 4 }
39
+ validates :new_address_yomi, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..75 }
40
+ validates :new_address, charset: { accept: [:all] }, sjis_bytesize: { in: 0..74 }, allow_blank: true
41
+ validates :updated_at, timeliness: { on_or_before: :today, type: :date }
42
+ validates :ip_name_yomi, charset: { accept: [:katakana] }, sjis_bytesize: { in: 1..25 }
43
+ validates :ip_name, charset: { accept: [:all] }, sjis_bytesize: { in: 0..24 }, allow_blank: true
44
+ validates :old_address_yomi, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..75 }
45
+ validates :old_address, charset: { accept: [:all] }, sjis_bytesize: { in: 0..74 }, allow_blank: true
46
+ validates :memo, charset: { accept: [:all] }, sjis_bytesize: { in: 0..75 }, allow_blank: true
47
+
48
+ define_format_date_method :birth_at, :updated_at
49
+ define_code_mapper_method :birth_at_era_nengo, :updated_at_era_nengo
50
+
51
+ def initialize
52
+ yield(self) if block_given?
53
+ end
54
+
55
+ def to_csv
56
+ [
57
+ DOC_CODE,
58
+ area_code,
59
+ office_code,
60
+ ip_code,
61
+ basic_pension_number1,
62
+ basic_pension_number2,
63
+ mapped_birth_at_era_nengo,
64
+ fmt_era_ymd_birth_at,
65
+ zip_code1,
66
+ zip_code2,
67
+ new_address_yomi,
68
+ new_address,
69
+ mapped_updated_at_era_nengo,
70
+ fmt_era_ymd_updated_at,
71
+ ip_name_yomi,
72
+ ip_name,
73
+ old_address_yomi,
74
+ old_address,
75
+ memo
76
+ ].join(',')
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ require 'virtus'
3
+ require 'active_model'
4
+
5
+ module Kirico
6
+ class Company
7
+ include Virtus.model
8
+ include ActiveModel::Validations
9
+
10
+ attribute :area_code, String
11
+ attribute :office_code, String
12
+ attribute :office_number, String
13
+ attribute :zip_code1, String
14
+ attribute :zip_code2, String
15
+ attribute :address, String
16
+ attribute :name, String
17
+ attribute :owner_name, String
18
+ attribute :tel_number, String
19
+
20
+ validates :area_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
21
+ validates :office_code, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..4 }
22
+ validates :office_number, charset: { accept: [:numeric] }, sjis_bytesize: { in: 1..5 }
23
+ validates :zip_code1, charset: { accept: [:numeric] }, sjis_bytesize: { is: 3 }
24
+ validates :zip_code2, charset: { accept: [:numeric] }, sjis_bytesize: { is: 4 }
25
+ validates :address, charset: { accept: [:all] }, sjis_bytesize: { in: 1..75 }
26
+ validates :name, charset: { accept: [:katakana, :kanji] }, sjis_bytesize: { in: 1..50 }
27
+ validates :owner_name, charset: { accept: [:katakana, :kanji] }, sjis_bytesize: { in: 1..25 }
28
+ validates :tel_number, charset: { accept: [:latin, :number] }, sjis_bytesize: { in: 1..12 }
29
+
30
+ def initialize
31
+ yield(self) if block_given?
32
+ end
33
+
34
+ def to_csv
35
+ [
36
+ area_code,
37
+ office_code,
38
+ office_number,
39
+ zip_code1,
40
+ zip_code2,
41
+ address,
42
+ name,
43
+ owner_name,
44
+ tel_number
45
+ ].join(',')
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'virtus'
3
+
4
+ module Kirico
5
+ class CompanyCount
6
+ include Virtus.model
7
+
8
+ COUNT = '001'
9
+
10
+ def initialize
11
+ super
12
+ end
13
+
14
+ def to_csv
15
+ [nil, COUNT].join(',')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'virtus'
3
+
4
+ module Kirico
5
+ class CompanyIdentifier
6
+ include Virtus.model
7
+
8
+ IDENTIFIER = '[kanri]'
9
+
10
+ def to_csv
11
+ [IDENTIFIER].join(',')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'virtus'
3
+
4
+ module Kirico
5
+ class DataIdentifier
6
+ include Virtus.model
7
+
8
+ IDENTIFIER = '[data]'
9
+
10
+ def to_csv
11
+ [IDENTIFIER].join(',')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ require 'virtus'
3
+ require 'active_model'
4
+ require 'kirico/models/helper'
5
+
6
+ module Kirico
7
+ class FDManagementRecord
8
+ include Virtus.model
9
+ include ActiveModel::Validations
10
+ extend Kirico::Helper
11
+
12
+ MAIN_DOC_CODE = '22223'
13
+
14
+ attribute :area_code, String
15
+ attribute :office_code, String
16
+ attribute :fd_seq_number, String
17
+ attribute :created_at, Date
18
+
19
+ validates :area_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
20
+ validates :office_code, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..4 }
21
+ validates :fd_seq_number, charset: { accept: [:numeric] }, sjis_bytesize: { is: 3 }
22
+
23
+ define_format_date_method :created_at
24
+
25
+ def initialize
26
+ yield(self) if block_given?
27
+ end
28
+
29
+ def to_csv
30
+ [
31
+ area_code,
32
+ office_code,
33
+ fd_seq_number,
34
+ fmt_ymd_created_at,
35
+ MAIN_DOC_CODE
36
+ ].join(',')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+ require 'era_ja'
3
+ require 'active_support/core_ext/object'
4
+ require 'yaml'
5
+ require 'kirico/validators/charset_validator'
6
+ require 'kirico/validators/sjis_bytesize_validator'
7
+
8
+ module Kirico
9
+ module Helper
10
+ # Validator の追加
11
+ ActiveModel::Validations::CharsetValidator = Kirico::CharsetValidator
12
+ ActiveModel::Validations::SjisBytesizeValidator = Kirico::SjisBytesizeValidator
13
+
14
+ # 指定した date 型のフィールドを整形するメソッドを生やす
15
+ #
16
+ # 例:
17
+ # created_at メソッドを整形
18
+ #
19
+ # # 2015/04/09 => 20150409
20
+ # def fmt_ymd_created_at
21
+ # return nil if submit_at.nil?
22
+ # submit_at.try(:to_era, '%Y%m%d')
23
+ # end
24
+ #
25
+ # # 2015/04/09 => 270409
26
+ # def fmt_era_ymd_created_at
27
+ # return nil if submit_at.nil?
28
+ # submit_at.try(:to_era, '%E%m%d')
29
+ # end
30
+ #
31
+ # # 2015/04/09 => H
32
+ # def submit_at_era_nengo
33
+ # submit_at.try(:to_era, '%o%E').try(:[], 0)
34
+ # end
35
+ #
36
+ # # 2015/04/09 => 平成
37
+ # def submit_at_era_nengo_kanji
38
+ # submit_at.try(:to_era, '%O%E').try(:gsub, /\d+\z/, '')
39
+ # end
40
+ def define_format_date_method(*fields)
41
+ fields.each do |attr_name|
42
+ define_method("fmt_ymd_#{attr_name}") do
43
+ send(attr_name).try(:strftime, '%Y%m%d')
44
+ end
45
+
46
+ define_method("fmt_era_ymd_#{attr_name}") do
47
+ send(attr_name).try(:to_era, '%E%m%d')
48
+ end
49
+
50
+ define_method("#{attr_name}_era_nengo") do
51
+ send(attr_name).try(:to_era, '%o%E').try(:[], 0)
52
+ end
53
+
54
+ define_method("#{attr_name}_era_nengo_kanji") do
55
+ send(attr_name).try(:to_era, '%O%E').try(:gsub, /\d+\z/, '')
56
+ end
57
+ end
58
+ end
59
+
60
+ # 指定したフィールドの値と区分値の値とをマッピングする
61
+ # メソッドを生やす。
62
+ # 対応表は models/mappers.ja.yml 参照
63
+ #
64
+ # 例:
65
+ # cause_cd フィールドをマッピングするメソッド
66
+ #
67
+ # def mapped_birth_at_era
68
+ # value = object.send('cause_cd').try(:to_sym)
69
+ # class_name = object.class.underscore
70
+ # I18n.t("mappers.#{class_name}")[attr_name][value]
71
+ # end
72
+ def define_code_mapper_method(*fields)
73
+ fields.each do |attr_name|
74
+ define_method("mapped_#{attr_name}") do
75
+ value = send(attr_name)
76
+ return if value.nil?
77
+ class_name = self.class.name.underscore
78
+ @mappers ||= YAML.load_file(File.join(__dir__, 'mappers.yml'))
79
+ @mappers['mappers'][class_name.to_s].try(:[], attr_name.to_s).try(:[], value.to_s)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,16 @@
1
+ mappers:
2
+ helper_mock:
3
+ gender:
4
+ 男性: 0
5
+ 女性: 1
6
+ kirico/changing_address_record:
7
+ birth_at_era_nengo:
8
+ M: 1
9
+ T: 3
10
+ S: 5
11
+ H: 7
12
+ updated_at_era_nengo:
13
+ M: 1
14
+ T: 3
15
+ S: 5
16
+ H: 7
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+ require 'active_model'
3
+ require 'active_model/validator'
4
+
5
+ # 文字種別を検証する
6
+ #
7
+ # 設定例:
8
+ # validate :area_code, charset: { accept: [:numeric] }
9
+ # validate :office_code, charset: { accept: [:numeric, :latin, :katakana] }
10
+ # validate :office_address, charset: { accept: [:all] }
11
+ # validate :office_name, charset: { accept: [:kanji, :katakana] }
12
+ #
13
+ # accept に指定可能なオプション:
14
+ #
15
+ # :numeric
16
+ # 0~9 の1 バイトの半角文字
17
+ #
18
+ # :latin
19
+ # アルファベットおよび記号の 1 バイトの半角文字
20
+ #
21
+ # :katakana
22
+ # カタカナの1バイトの半角文字(スペースを含む)
23
+ #
24
+ # :kanji
25
+ # 2 バイトの全角文字
26
+ # see: http://charset.7jp.net/sjis2.html
27
+ #
28
+ # 特殊記号(間隔) 8140
29
+ # 特殊記号(記述記号) 8141-8164
30
+ # 特殊記号(括弧記号) 8165-817A
31
+ # 特殊記号(学術記号) 817B-818A
32
+ # 特殊記号(単位記号) 818B-8193
33
+ # 特殊記号(一般記号) 8194-819E, 819F-81AC
34
+ # 数字 824F-8258
35
+ # ローマ字 8260-8279, 8281-829A
36
+ # 平仮名 829F-82F1
37
+ # 片仮名 8340-8396
38
+ # ギリシア文字 839F-83B6, 83BF-83D6
39
+ # ロシア文字 8440-8460, 8470-8491
40
+ # 漢字 889F-9872, 989F-EAA4
41
+ module Kirico
42
+ class CharsetValidator < ActiveModel::EachValidator
43
+ NUMERIC_RULE = '0-9'
44
+ LATIN_RULE = 'A-Za-z\- '
45
+ KATAKANA_RULE = ' ヲ-゚'
46
+ KANJI_RULE = ' -〓0-я亜-腕弌-熙'
47
+
48
+ CHECKS = {
49
+ numeric: NUMERIC_RULE,
50
+ latin: LATIN_RULE,
51
+ katakana: KATAKANA_RULE,
52
+ kanji: KANJI_RULE,
53
+ all: [NUMERIC_RULE, LATIN_RULE, KATAKANA_RULE, KANJI_RULE].join
54
+ }.freeze
55
+
56
+ def check_validity!
57
+ keys = CHECKS.keys & ([options[:accept]].flatten || [])
58
+ raise ArgumentError, ':accept unspecified. Specify the :numeric, :latin, :katakana, :kanji, or :all option.' if keys.empty?
59
+ end
60
+
61
+ def validate_each(record, attribute, value)
62
+ error_chars = retrieve_error_chars(value)
63
+
64
+ record.errors.add(attribute, (options[:message] || :invalid_charset), error_chars: error_chars.join(', ')) unless error_chars.empty?
65
+ end
66
+
67
+ def retrieve_error_chars(value, error_chars = [])
68
+ # value.blank? はタブ文字等の場合でも true となるため注意
69
+ return error_chars if value.nil? || value.empty?
70
+
71
+ match = regex(options[:accept]).match(value.encode('CP932'))
72
+ return error_chars if match.nil?
73
+
74
+ ch = match.captures[0].encode('UTF-8')
75
+ error_chars << ch
76
+ retrieve_error_chars(value.gsub(/#{ch}/, ''), error_chars)
77
+ rescue Encoding::UndefinedConversionError => e
78
+ ch = e.error_char
79
+ error_chars << ch
80
+ retrieve_error_chars(value.gsub(/#{ch}/, ''), error_chars)
81
+ end
82
+
83
+ private
84
+
85
+ def regex(accept = [])
86
+ joined_rules = CHECKS.select { |k, _v| accept.include?(k) }.values.join
87
+ str = "[^#{joined_rules}]".encode('CP932')
88
+ /(#{str})/
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+ require 'active_model'
3
+ require 'active_model/validator'
4
+
5
+ # SJIS 換算の文字長を検証する
6
+ #
7
+ # 設定例:
8
+ # validate :address, sjis_bytesize: { in: 1..30 }
9
+ #
10
+ # 参考: https://github.com/rails/rails/blob/fe1f4b2ad56f010a4e9b93d547d63a15953d9dc2/activemodel/lib/active_model/validations/length.rb
11
+ module Kirico
12
+ class SjisBytesizeValidator < ActiveModel::EachValidator
13
+ MESSAGES = { is: :wrong_length, minimum: :too_short, maximum: :too_long }.freeze
14
+ CHECKS = { is: :==, minimum: :>=, maximum: :<= }.freeze
15
+
16
+ RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :too_short, :too_long]
17
+
18
+ def initialize(options)
19
+ range = (options.delete(:in) || options.delete(:within))
20
+ if range
21
+ raise ArgumentError, ':in and :within must be a Range' unless range.is_a?(Range)
22
+ options[:minimum] = range.min
23
+ options[:maximum] = range.max
24
+ end
25
+
26
+ if options[:allow_blank] == false && options[:minimum].nil? && options[:is].nil?
27
+ options[:minimum] = 1
28
+ end
29
+
30
+ super
31
+ end
32
+
33
+ def check_validity!
34
+ keys = CHECKS.keys & options.keys
35
+
36
+ if keys.empty?
37
+ raise ArgumentError, 'Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option.'
38
+ end
39
+
40
+ keys.each do |key|
41
+ value = options[key]
42
+
43
+ unless (value.is_a?(Integer) && value >= 0) || value == Float::INFINITY
44
+ raise ArgumentError, ":#{key} must be a nonnegative Integer or Infinity"
45
+ end
46
+ end
47
+ end
48
+
49
+ def validate_each(record, attribute, value = '')
50
+ value_length = value.to_s.encode('Shift_JIS').bytesize
51
+
52
+ errors_options = options.except(*RESERVED_OPTIONS)
53
+
54
+ CHECKS.each do |key, validity_check|
55
+ check_value = options[key]
56
+ next unless check_value
57
+
58
+ if !value.nil? || skip_nil_check?(key)
59
+ next if value_length.send(validity_check, check_value)
60
+ end
61
+
62
+ errors_options[:count] = check_value
63
+
64
+ default_message = options[MESSAGES[key]]
65
+ errors_options[:message] ||= default_message if default_message
66
+
67
+ record.errors.add(attribute, MESSAGES[key], errors_options)
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def skip_nil_check?(key)
74
+ key == :maximum && options[:allow_nil].nil? && options[:allow_blank].nil?
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module Kirico
3
+ VERSION = '0.1.0'
4
+ end
metadata ADDED
@@ -0,0 +1,284 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kirico
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kakipo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: era_ja
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: validates_timeliness
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: virtus
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: factory_girl
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-bundler
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: guard-rubocop
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: pry-byebug
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ description: Write a longer description or delete this line.
224
+ email:
225
+ - kakipo@gmail.com
226
+ executables: []
227
+ extensions: []
228
+ extra_rdoc_files: []
229
+ files:
230
+ - ".gitignore"
231
+ - ".rspec"
232
+ - ".rubocop.yml"
233
+ - ".rubocop_todo.yml"
234
+ - ".ruby-version"
235
+ - Gemfile
236
+ - Guardfile
237
+ - LICENSE.txt
238
+ - README.md
239
+ - Rakefile
240
+ - bin/console
241
+ - bin/setup
242
+ - circle.yml
243
+ - kirico.gemspec
244
+ - lib/kirico.rb
245
+ - lib/kirico/config/locales/en.yml
246
+ - lib/kirico/config/locales/ja.yml
247
+ - lib/kirico/csv_generator.rb
248
+ - lib/kirico/models/changing_address_record.rb
249
+ - lib/kirico/models/company.rb
250
+ - lib/kirico/models/company_count.rb
251
+ - lib/kirico/models/company_identifier.rb
252
+ - lib/kirico/models/data_identifier.rb
253
+ - lib/kirico/models/fd_management_record.rb
254
+ - lib/kirico/models/helper.rb
255
+ - lib/kirico/models/mappers.yml
256
+ - lib/kirico/validators/charset_validator.rb
257
+ - lib/kirico/validators/sjis_bytesize_validator.rb
258
+ - lib/kirico/version.rb
259
+ homepage: https://github.com/kufu/kirico
260
+ licenses:
261
+ - MIT
262
+ metadata:
263
+ allowed_push_host: https://rubygems.org
264
+ post_install_message:
265
+ rdoc_options: []
266
+ require_paths:
267
+ - lib
268
+ required_ruby_version: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - ">="
271
+ - !ruby/object:Gem::Version
272
+ version: 2.3.1
273
+ required_rubygems_version: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - ">="
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ requirements: []
279
+ rubyforge_project:
280
+ rubygems_version: 2.5.1
281
+ signing_key:
282
+ specification_version: 4
283
+ summary: Write a short summary, because Rubygems requires one.
284
+ test_files: []