kirico 0.1.8 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c2767cdde59cee47581c09661a6a46c3df6e7dd
4
- data.tar.gz: 7c5c882a0af530c80041ec6c80a538447b1dbf80
3
+ metadata.gz: 56463d9a6a89888312ad92779ee4049b72d416a3
4
+ data.tar.gz: ab1ecea3a60a0804854950e53cb2ec7e70426694
5
5
  SHA512:
6
- metadata.gz: e6b2eb63e46031144d6563867f35301caec257fdf8453d500509ba6097b3c3baf4c731d8478cca16e8f96345d3a0fff845a669113d57fe9b18b04961a5a201a1
7
- data.tar.gz: 3460888dd77d96b95ee1b4f4191e851c216e160ec0a15c03dcf0dabed011a3664c53750eb65d2d9114161f01c3e14e0607ec018540a1ec24d9257a8e0f0a88b1
6
+ metadata.gz: b5a685c91a03430714777ca52c20481894279947b59d570f155bd0be04da9a86836d99ec52a14f20e0d068a6879fb1b5f03c12abca864502a86a1e4dbed85c7f
7
+ data.tar.gz: b14f1888b21b8633604b1619fcd6cf09682695296fd15eed97321fc9237741aed4ddca3c2cf0fddb63fd7c19fc700fb8c00120d1d3d7c1d85e8f33aeac7d552f
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017 Kensuke NAITO and KUFU, Inc.
1
+ Copyright (c) 2017 Kensuke NAITO and SmartHR, Inc.
2
2
 
3
3
  以下に定める条件に従い、本ソフトウェアおよび関連文書のファイル(以下「ソフトウェア」)の複製を取得するすべての人に対し、ソフトウェアを無制限に扱うことを無償で許可します。これには、ソフトウェアの複製を使用、複写、変更、結合、掲載、頒布、サブライセンス、および/または販売する権利、およびソフトウェアを提供する相手に同じことを許可する権利も無制限に含まれます。
4
4
 
data/README.md CHANGED
@@ -104,7 +104,7 @@ require 'i18n'
104
104
  I18n.locale = :ja
105
105
 
106
106
  # 住所変更届データレコード
107
- address_record = Kirico::ChangingAddressRecord.new do |rec|
107
+ address_record = Kirico::DataRecord22187041.new do |rec|
108
108
  rec.area_code = '03'
109
109
  rec.office_code = 'キリコ'
110
110
  rec.ip_code = '100'
@@ -178,17 +178,17 @@ end
178
178
 
179
179
  | データレコード | クラス名 | 実装状況 |
180
180
  | ------ | ------ | ------ |
181
- | 資格取得届データレコード | TBD | △ |
182
- | 資格喪失届データレコード | TBD | △ |
183
- | 住所変更届データレコード | Kirico::ChangingAddressRecord | ◯ |
184
- | 算定基礎届データレコード | TBD | |
185
- | 月額変更届データレコード | TBD | △ |
186
- | 賞与支払届データレコード | TBD | △ |
187
- | 被扶養者(異動)届データレコード | TBD | △ |
188
- | 3号関係届(資格取得)データレコード | TBD | △ |
189
- | 3号関係届(資格喪失)データレコード | TBD | △ |
190
- | 3号関係届(志望)データレコード | TBD | △ |
191
- | 国民年金第3号被保険者<br>被扶養配偶者非該当届データレコード | TBD | △ |
181
+ | 資格取得届データレコード | Kirico::DataRecord22007041 | △ |
182
+ | 資格喪失届データレコード | Kirico::DataRecord22017041 | △ |
183
+ | 住所変更届データレコード | Kirico::DataRecord22187041 | ◯ |
184
+ | 算定基礎届データレコード | Kirico::DataRecord22257041 | |
185
+ | 月額変更届データレコード | Kirico::DataRecord22217041 | △ |
186
+ | 賞与支払届データレコード | Kirico::DataRecord22657041 | △ |
187
+ | 被扶養者(異動)届データレコード | Kirico::DataRecord22027051 | △ |
188
+ | 3号関係届(資格取得)データレコード | Kirico::DataRecord52805011 | △ |
189
+ | 3号関係届(資格喪失)データレコード | Kirico::DataRecord52805021 | △ |
190
+ | 3号関係届(死亡)データレコード | Kirico::DataRecord52805031 | △ |
191
+ | 国民年金第3号被保険者<br>被扶養配偶者非該当届データレコード | Kirico::DataRecord52811001 | △ |
192
192
 
193
193
 
194
194
  ※実装状況について
@@ -212,18 +212,18 @@ end
212
212
 
213
213
  ## Copyright
214
214
 
215
- Copyright (c) 2017 Kensuke NAITO and KUFU, Inc.
215
+ Copyright (c) 2017 Kensuke NAITO and SmartHR, Inc.
216
216
  ライセンスはこちら: [kirico/LICENSE.md](https://github.com/kufu/kirico/blob/master/LICENSE.md)
217
217
 
218
218
 
219
- # KUFU について
219
+ # SmartHR について
220
220
 
221
- ![KUFU logo](https://raw.githubusercontent.com/wiki/kufu/kiji/images/logo_kufu.png)
221
+ ![SmartHR logo](https://cloud.githubusercontent.com/assets/2214179/24910676/79ef6ada-1f03-11e7-856a-9f9737942867.png)
222
222
 
223
- kirico は株式会社 KUFU によってメンテナンス、開発が行われています。
223
+ kirico は株式会社 SmartHR によってメンテナンス、開発が行われています。
224
224
  わたしたちは OSS の力を信じています。
225
225
 
226
- KUFU では OSS 活動に積極的なエンジニアを募集しています!
226
+ SmartHR では OSS 活動に積極的なエンジニアを募集しています!
227
227
 
228
228
  [「雇用」×「国のAPI」をハックする Ruby エンジニア募集!](https://www.wantedly.com/projects/3788)
229
229
 
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  require 'kirico/version'
3
3
  require 'kirico/models/application_record'
4
- require 'kirico/models/changing_address_record'
5
4
  require 'kirico/models/company_count'
6
5
  require 'kirico/models/company_identifier'
7
6
  require 'kirico/models/company'
8
7
  require 'kirico/models/data_identifier'
8
+ require 'kirico/models/data_record22187041'
9
+ require 'kirico/models/data_record22257041'
9
10
  require 'kirico/models/fd_management_record'
10
11
  require 'kirico/models/helper'
11
12
  require 'kirico/models/form'
@@ -2,6 +2,7 @@ en:
2
2
  errors:
3
3
  messages:
4
4
  invalid_charset: "has invalid character(s): %{error_chars}"
5
+ invalid_space_divider: "must be dividied by %{space_type}"
5
6
  invalid_date: "is not a valid date"
6
7
  invalid_time: "is not a valid time"
7
8
  invalid_datetime: "is not a valid datetime"
@@ -10,3 +11,7 @@ en:
10
11
  on_or_before: "must be on or before %{restriction}"
11
12
  after: "must be after %{restriction}"
12
13
  on_or_after: "must be on or after %{restriction}"
14
+ space_type:
15
+ full_width: full width space
16
+ half_width: half width space
17
+ both_width: full/half width space
@@ -2,6 +2,7 @@ ja:
2
2
  errors:
3
3
  messages:
4
4
  invalid_charset: "に利用できない文字が入力されています。%{error_chars}"
5
+ invalid_space_divider: "は%{space_type}で区切ってください。"
5
6
  too_long: は%{count}文字以内で入力してください。
6
7
  too_short: は%{count}文字以上で入力してください。
7
8
  wrong_length: は%{count}文字で入力してください。
@@ -13,9 +14,13 @@ ja:
13
14
  on_or_before: "は %{restriction} 以前を指定してください。"
14
15
  after: "は %{restriction} より後を指定してください。"
15
16
  on_or_after: "は %{restriction} 以降を指定してください。"
17
+ space_type:
18
+ full_width: 全角スペース
19
+ half_width: 半角スペース
20
+ both_width: 全半角スペース
16
21
  activemodel:
17
22
  models:
18
- kirico/changing_address_record: 住所変更データレコード
23
+ kirico/data_record22187041: 住所変更届データレコード
19
24
  kirico/company_count: 事業所数情報
20
25
  kirico/company_identifier: 事業所識別符号
21
26
  kirico/company: 事業所情報
@@ -25,7 +30,8 @@ ja:
25
30
  kirico/sr_company_count: 事業所情報(事業所数)
26
31
  kirico/sr_fd_management_record: FD管理レコード
27
32
  attributes:
28
- kirico/changing_address_record:
33
+ # 住所変更届
34
+ kirico/data_record22187041:
29
35
  area_code: 都市区符号
30
36
  office_code: 事業所記号
31
37
  ip_code: 被保険者整理番号
@@ -42,6 +48,35 @@ ja:
42
48
  old_address_yomi: 変更前被保険者住所(カナ)
43
49
  old_address: 変更前被保険者住所(漢字)
44
50
  memo: 備考欄
51
+ # 算定基礎届
52
+ kirico/data_record22257041:
53
+ area_code: 都市区符号
54
+ office_code: 事業所記号
55
+ ip_code: 被保険者整理番号
56
+ birth_at: 生年月日
57
+ applied_at: 適用年月日
58
+ ip_name_yomi: 被保険者氏名(カナ)
59
+ ip_name: 被保険者氏名(漢字)
60
+ gender_type: 種別(性別)
61
+ old_monthly_standard_income_hel_ins: 従前の標準報酬月額(健保)
62
+ old_monthly_standard_income_pns_ins: 従前の標準報酬月額(厚保)
63
+ old_applied_at: 従前の改定年月日
64
+ apr_days: 支払基礎日数(4月)
65
+ may_days: 支払基礎日数(5月)
66
+ jun_days: 支払基礎日数(6月)
67
+ apr_income_currency: 通貨によるものの額(4月)
68
+ may_income_currency: 通貨によるものの額(5月)
69
+ jun_income_currency: 通貨によるものの額(6月)
70
+ apr_income_goods: 現物によるものの額(4月)
71
+ may_income_goods: 現物によるものの額(5月)
72
+ jun_income_goods: 現物によるものの額(6月)
73
+ avg_adjustment: 修正平均額
74
+ ip_type: 被保険者区分
75
+ retroacted_payment: 遡及支払額
76
+ income_updated_type: 昇(降)給区分
77
+ income_diff_amount: 昇(降)給差の月額
78
+ income_updated_at: 昇(降)給年月日
79
+ memo: 備考欄
45
80
  kirico/company:
46
81
  sr_name: 社会保険労務士氏名
47
82
  count: 事業所数情報
@@ -24,7 +24,7 @@ module Kirico
24
24
  validates :zip_code2, charset: { accept: [:numeric] }, sjis_bytesize: { is: 4 }
25
25
  validates :address, charset: { accept: [:all] }, sjis_bytesize: { in: 1..75 }
26
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 }
27
+ validates :owner_name, charset: { accept: [:katakana, :kanji] }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :both_width }
28
28
  validates :tel_number, charset: { accept: [:latin, :numeric] }, sjis_bytesize: { in: 1..12 }
29
29
 
30
30
  def initialize
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+ # 住所変更届データレコード
2
3
  module Kirico
3
- class ChangingAddressRecord < ApplicationRecord
4
+ class DataRecord22187041 < ApplicationRecord
4
5
  DOC_CODE = '22187041'
5
6
 
6
7
  attribute :area_code, String
@@ -30,8 +31,8 @@ module Kirico
30
31
  validates :new_address_yomi, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..75 }
31
32
  validates :new_address, charset: { accept: [:all] }, sjis_bytesize: { in: 0..74 }, allow_blank: true
32
33
  validates :updated_at, timeliness: { on_or_before: :today, type: :date }
33
- validates :ip_name_yomi, charset: { accept: [:katakana] }, sjis_bytesize: { in: 1..25 }
34
- validates :ip_name, charset: { accept: [:all] }, sjis_bytesize: { in: 0..24 }, allow_blank: true
34
+ validates :ip_name_yomi, charset: { accept: [:katakana] }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :half_width }
35
+ validates :ip_name, charset: { accept: [:all] }, sjis_bytesize: { in: 0..24 }, allow_blank: true, space_divider: { space: :full_width }
35
36
  validates :old_address_yomi, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..75 }
36
37
  validates :old_address, charset: { accept: [:all] }, sjis_bytesize: { in: 0..74 }, allow_blank: true
37
38
  validates :memo, charset: { accept: [:all] }, sjis_bytesize: { in: 0..75 }, allow_blank: true
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+ # 算定基礎届データレコード
3
+ module Kirico
4
+ class DataRecord22257041 < ApplicationRecord
5
+ DOC_CODE = '22257041'
6
+ COVERED_MONTHS = [:apr, :may, :jun].freeze
7
+
8
+ attribute :area_code, String
9
+ attribute :office_code, String
10
+ attribute :ip_code, String
11
+ attribute :birth_at, Date
12
+ attribute :applied_at, Date
13
+ attribute :ip_name_yomi, String
14
+ attribute :ip_name, String
15
+ attribute :gender_type, Symbol
16
+ attribute :old_monthly_standard_income_hel_ins, Integer
17
+ attribute :old_monthly_standard_income_pns_ins, Integer
18
+ attribute :old_applied_at, Date
19
+ COVERED_MONTHS.each do |month|
20
+ attribute "#{month}_days", Integer
21
+ attribute "#{month}_income_currency", Integer
22
+ attribute "#{month}_income_goods", Integer
23
+ end
24
+ attribute :avg_adjustment, Integer
25
+ attribute :ip_type, Symbol
26
+ attribute :retroacted_payment, Integer
27
+ attribute :income_updated_type, Symbol
28
+ attribute :income_diff_amount, Integer
29
+ attribute :income_updated_at, Date
30
+ attribute :memo, String
31
+
32
+ define_format_date_method :birth_at, :applied_at, :old_applied_at, :income_updated_at
33
+ define_code_mapper_method :birth_at_era_nengo, :applied_at_era_nengo,
34
+ :old_applied_at_era_nengo, :income_updated_at_era_nengo,
35
+ :gender_type, :ip_type, :income_updated_type
36
+ define_in_k_method :old_monthly_standard_income_hel_ins, :old_monthly_standard_income_pns_ins
37
+
38
+ validates :area_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
39
+ validates :office_code, charset: { accept: [:numeric, :latin, :katakana] }, sjis_bytesize: { in: 1..4 }
40
+ validates :ip_code, charset: { accept: [:numeric] }, sjis_bytesize: { in: 1..6 }
41
+ validates :applied_at, timeliness: { on_or_after: -> { Date.new(1989, 1, 8) }, type: :date }
42
+ validates :ip_name_yomi, charset: { accept: [:katakana] }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :half_width }
43
+ validates :ip_name, charset: { accept: [:all] }, sjis_bytesize: { in: 0..24 }, allow_blank: true, space_divider: { space: :full_width }
44
+ validates :gender_type, inclusion: { in: [:gender_type_1, :gender_type_2, :gender_type_3, :gender_type_5, :gender_type_6, :gender_type_7] }
45
+ validates :old_monthly_standard_income_hel_ins, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
46
+ validates :old_monthly_standard_income_pns_ins, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
47
+ validates :old_applied_at, timeliness: { on_or_after: -> { Date.new(1989, 1, 8) }, type: :date }
48
+ validates :apr_days, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 30 }
49
+ validates :may_days, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 31 }
50
+ validates :jun_days, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 30 }
51
+ COVERED_MONTHS.each do |month|
52
+ validates "#{month}_income_currency", numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }
53
+ validates "#{month}_income_goods", numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }
54
+ end
55
+ validates :avg_adjustment, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
56
+ validates :ip_type, inclusion: { in: [:ip_type_0, :ip_type_1, :ip_type_2] }
57
+ validates :retroacted_payment, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
58
+ validates :income_updated_type, inclusion: { in: [:income_updated_type_0, :income_updated_type_1] }, allow_blank: true
59
+ validates :income_diff_amount, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
60
+ validates :income_updated_at, timeliness: { on_or_after: -> { Date.new(1989, 1, 8) }, type: :date }, allow_blank: true
61
+ validates :memo, charset: { accept: [:all] }, sjis_bytesize: { in: 0..75 }, allow_blank: true
62
+
63
+ def initialize
64
+ yield(self) if block_given?
65
+ end
66
+
67
+ # rubocop:disable all
68
+ def to_csv
69
+ [
70
+ DOC_CODE,
71
+ area_code,
72
+ office_code,
73
+ ip_code,
74
+ mapped_birth_at_era_nengo,
75
+ fmt_era_ymd_birth_at,
76
+ '',
77
+ mapped_applied_at_era_nengo,
78
+ applied_at_era_year,
79
+ applied_at_month,
80
+ ip_name_yomi,
81
+ ip_name,
82
+ mapped_gender_type,
83
+ old_monthly_standard_income_hel_ins.nil? ? nil : old_monthly_standard_income_hel_ins_in_k.to_s.rjust(4, '0'),
84
+ old_monthly_standard_income_pns_ins.nil? ? nil : old_monthly_standard_income_pns_ins_in_k.to_s.rjust(4, '0'),
85
+ mapped_old_applied_at_era_nengo,
86
+ old_applied_at_era_year,
87
+ old_applied_at_month,
88
+ '04',
89
+ '05',
90
+ '06',
91
+ apr_days.to_s.rjust(2, '0'),
92
+ may_days.to_s.rjust(2, '0'),
93
+ jun_days.to_s.rjust(2, '0'),
94
+ apr_income_currency.to_s.rjust(7, '0'),
95
+ may_income_currency.to_s.rjust(7, '0'),
96
+ jun_income_currency.to_s.rjust(7, '0'),
97
+ apr_income_goods.to_s.rjust(7, '0'),
98
+ may_income_goods.to_s.rjust(7, '0'),
99
+ jun_income_goods.to_s.rjust(7, '0'),
100
+ income_total(apr_income_currency, apr_income_goods).to_s.rjust(7, '0'),
101
+ income_total(may_income_currency, may_income_goods).to_s.rjust(7, '0'),
102
+ income_total(jun_income_currency, jun_income_goods).to_s.rjust(7, '0'),
103
+ income_average.to_s.rjust(7, '0'),
104
+ avg_adjustment.nil? ? nil : avg_adjustment.to_s.rjust(7, '0'),
105
+ mapped_ip_type,
106
+ '',
107
+ '',
108
+ '',
109
+ retroacted_payment.nil? ? nil : retroacted_payment.to_s.rjust(7, '0'),
110
+ mapped_income_updated_type,
111
+ income_diff_amount.nil? ? nil : income_diff_amount.to_s.rjust(7, '0'),
112
+ income_updated_at.nil? ? nil : income_updated_at_era_year,
113
+ income_updated_at.nil? ? nil : income_updated_at_month,
114
+ memo
115
+ ].map { |attr| attr.to_s.encode('CP932') }.join(',')
116
+ end
117
+ # rubocop:enable all
118
+
119
+ def income_total(currency, goods)
120
+ total = currency.to_i + goods.to_i
121
+ total < 10_000_000 ? total : 9_999_999
122
+ end
123
+
124
+ # 平均額を計算する
125
+ #
126
+ # 算定対象月の合計値を算定対象月数で割った値を返す。
127
+ #
128
+ # ただし、
129
+ # - 1 円未満は切り捨て
130
+ # - 10,000,000 円以上は 9,999,999 を返す
131
+ # - 算定対象月が存在しない場合は「0」を返す
132
+ def income_average
133
+ return 0 if target_months.empty?
134
+ total = target_months.map do |month|
135
+ send("#{month}_income_currency").to_i + send("#{month}_income_goods").to_i
136
+ end.inject(:+)
137
+ avg = total / target_months.length
138
+ avg < 10_000_000 ? avg : 9_999_999
139
+ end
140
+
141
+ # 算定対象月の配列を返却するs
142
+ #
143
+ # 1. 一般の被保険者の場合
144
+ # 17 日以上の月を対象とする
145
+ #
146
+ # 2. 短時間労働者の場合
147
+ # 11 日以上の月を対象とする
148
+ #
149
+ # 3. パートタイマーの場合
150
+ # 17 日以上の月を対象とする。
151
+ # ただし、全ての算定基礎月の支払基礎日数が 17 日未満の場合は、
152
+ # 15 日以上の月を対象とする。
153
+ def target_months
154
+ threshold = case ip_type
155
+ when :ip_type_0
156
+ 17
157
+ when :ip_type_1
158
+ COVERED_MONTHS.all? { |month| send("#{month}_days").to_i < 17 } ? 15 : 17
159
+ when :ip_type_2
160
+ 11
161
+ else
162
+ 17
163
+ end
164
+ COVERED_MONTHS.select { |month| threshold <= send("#{month}_days").to_i }
165
+ end
166
+ end
167
+ end
@@ -4,12 +4,14 @@ require 'active_support/core_ext/object'
4
4
  require 'yaml'
5
5
  require 'kirico/validators/charset_validator'
6
6
  require 'kirico/validators/sjis_bytesize_validator'
7
+ require 'kirico/validators/space_divider_validator'
7
8
 
8
9
  module Kirico
9
10
  module Helper
10
11
  # Validator の追加
11
12
  ActiveModel::Validations::CharsetValidator = Kirico::CharsetValidator
12
13
  ActiveModel::Validations::SjisBytesizeValidator = Kirico::SjisBytesizeValidator
14
+ ActiveModel::Validations::SpaceDividerValidator = Kirico::SpaceDividerValidator
13
15
 
14
16
  # 指定した date 型のフィールドを整形するメソッドを生やす
15
17
  #
@@ -37,6 +39,21 @@ module Kirico
37
39
  # def submit_at_era_nengo_kanji
38
40
  # submit_at.try(:to_era, '%O%E').try(:gsub, /\d+\z/, '')
39
41
  # end
42
+ #
43
+ # # 2015/04/09 => 2015
44
+ # def submit_at_year
45
+ # submit_at.try(:strftime, '%Y')
46
+ # end
47
+ #
48
+ # # 2015/04/09 => 04
49
+ # def submit_at_month
50
+ # submit_at.try(:strftime, '%m')
51
+ # end
52
+ #
53
+ # 2015/04/09 => 09
54
+ # def submit_at_day
55
+ # submit_at.try(:strftime, '%d')
56
+ # end
40
57
  def define_format_date_method(*fields)
41
58
  fields.each do |attr_name|
42
59
  define_method("fmt_ymd_#{attr_name}") do
@@ -54,6 +71,18 @@ module Kirico
54
71
  define_method("#{attr_name}_era_nengo_kanji") do
55
72
  send(attr_name).try(:to_era, '%O%E').try(:gsub, /\d+\z/, '')
56
73
  end
74
+
75
+ define_method("#{attr_name}_era_year") do
76
+ send(attr_name).try(:to_era, '%E')
77
+ end
78
+
79
+ define_method("#{attr_name}_month") do
80
+ send(attr_name).try(:strftime, '%m')
81
+ end
82
+
83
+ define_method("#{attr_name}_day") do
84
+ send(attr_name).try(:strftime, '%d')
85
+ end
57
86
  end
58
87
  end
59
88
 
@@ -80,5 +109,32 @@ module Kirico
80
109
  end
81
110
  end
82
111
  end
112
+
113
+ # 10^3 を単位とした値を返すメソッドを生やす
114
+ #
115
+ # 例:
116
+ # def monthly_income_currency_in_k
117
+ # return nil if object.monthly_income_currency.nil?
118
+ # return 0 if object.monthly_income_currency == 0
119
+ # (object.monthly_income_currency.to_f / 1000).round(0)
120
+ # end
121
+ def define_in_k_method(*fields, op: :round, precision: 0)
122
+ fields.each do |attr_name|
123
+ define_method("#{attr_name}_in_k") do
124
+ original = send(attr_name)
125
+ return nil if original.nil?
126
+
127
+ # 浮動小数点対応
128
+ n = BigDecimal(original.to_s) / BigDecimal('1000')
129
+ x = case op
130
+ when :round
131
+ n.send(op, precision)
132
+ else
133
+ n.send(op)
134
+ end
135
+ format("%.#{precision}f", x)
136
+ end
137
+ end
138
+ end
83
139
  end
84
140
  end
@@ -3,7 +3,8 @@ mappers:
3
3
  gender:
4
4
  男性: 0
5
5
  女性: 1
6
- kirico/changing_address_record:
6
+ # 住所変更届
7
+ kirico/data_record22187041:
7
8
  birth_at_era_nengo:
8
9
  M: 1
9
10
  T: 3
@@ -14,3 +15,39 @@ mappers:
14
15
  T: 3
15
16
  S: 5
16
17
  H: 7
18
+ # 算定基礎届
19
+ kirico/data_record22257041:
20
+ birth_at_era_nengo:
21
+ M: 1
22
+ T: 3
23
+ S: 5
24
+ H: 7
25
+ applied_at_era_nengo:
26
+ M: 1
27
+ T: 3
28
+ S: 5
29
+ H: 7
30
+ old_applied_at_era_nengo:
31
+ M: 1
32
+ T: 3
33
+ S: 5
34
+ H: 7
35
+ income_updated_at_era_nengo:
36
+ M: 1
37
+ T: 3
38
+ S: 5
39
+ H: 7
40
+ gender_type:
41
+ gender_type_1: 1
42
+ gender_type_2: 2
43
+ gender_type_3: 3
44
+ gender_type_5: 5
45
+ gender_type_6: 6
46
+ gender_type_7: 7
47
+ ip_type:
48
+ ip_type_0: 0
49
+ ip_type_1: 1
50
+ ip_type_2: 2
51
+ income_updated_type:
52
+ income_updated_type_0: 0
53
+ income_updated_type_1: 1
@@ -8,7 +8,7 @@ module Kirico
8
8
 
9
9
  attribute :name, String
10
10
 
11
- validates :name, charset: { accept: [:katakana, :kanji] }, sjis_bytesize: { in: 1..25 }
11
+ validates :name, charset: { accept: [:katakana, :kanji] }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :both_width }
12
12
 
13
13
  def to_csv
14
14
  [name, COUNT].map { |attr| attr.to_s.encode('CP932') }.join(',')
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ require 'active_model'
3
+ require 'active_model/validator'
4
+ require 'active_model/validations/format'
5
+
6
+ # 文字種別を検証する
7
+ #
8
+ # 設定例:
9
+ # validate :name, space_divider: { space: :full_width }
10
+ # validate :name_yomi, space_divider: { space: :half_width }
11
+ # validate :name, space_divider: { space: :both_width }
12
+ #
13
+ # space に指定可能なオプション:
14
+ #
15
+ # :full_width
16
+ # 全角スペース
17
+ #
18
+ # :half_width
19
+ # 半角スペース
20
+ #
21
+ # :both_width(デフォルト)
22
+ # 半角、全角問わない
23
+ module Kirico
24
+ class SpaceDividerValidator < ActiveModel::EachValidator
25
+ HALF_WIDTH_SPACE_RULE = ' '
26
+ FULL_WIDTH_SPACE_RULE = ' '
27
+ BOTH_WIDTH_SPACE_RULE = '[  ]'
28
+
29
+ def self.regexp(space_divider_rule)
30
+ /\A[^\p{blank}]+(#{space_divider_rule}[^\p{blank}]+)+\z/
31
+ end
32
+
33
+ CHECKS = {
34
+ half_width: regexp(HALF_WIDTH_SPACE_RULE),
35
+ full_width: regexp(FULL_WIDTH_SPACE_RULE),
36
+ both_width: regexp(BOTH_WIDTH_SPACE_RULE)
37
+ }.freeze
38
+
39
+ def check_validity!
40
+ raise ArgumentError, "Invalid space option #{space_option}. Specify the :full_width, half_width, or :both_width." unless CHECKS.keys.include?(space_option)
41
+ end
42
+
43
+ def validate_each(record, attribute, value)
44
+ record.errors.add(attribute, (options[:message] || :invalid_space_divider), space_type: space_type_i18n) if value.to_s !~ CHECKS[space_option]
45
+ end
46
+
47
+ private
48
+
49
+ def space_option
50
+ options[:space] || :both_width
51
+ end
52
+
53
+ def space_type_i18n
54
+ I18n.t('space_type')[space_option]
55
+ end
56
+ end
57
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kirico
3
- VERSION = '0.1.8'
3
+ VERSION = '1.0.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kirico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kakipo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-28 00:00:00.000000000 Z
11
+ date: 2017-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -262,11 +262,12 @@ files:
262
262
  - lib/kirico/models/application_record.rb
263
263
  - lib/kirico/models/base_company_count.rb
264
264
  - lib/kirico/models/base_fd_management_record.rb
265
- - lib/kirico/models/changing_address_record.rb
266
265
  - lib/kirico/models/company.rb
267
266
  - lib/kirico/models/company_count.rb
268
267
  - lib/kirico/models/company_identifier.rb
269
268
  - lib/kirico/models/data_identifier.rb
269
+ - lib/kirico/models/data_record22187041.rb
270
+ - lib/kirico/models/data_record22257041.rb
270
271
  - lib/kirico/models/fd_management_record.rb
271
272
  - lib/kirico/models/form.rb
272
273
  - lib/kirico/models/helper.rb
@@ -275,6 +276,7 @@ files:
275
276
  - lib/kirico/models/sr_fd_management_record.rb
276
277
  - lib/kirico/validators/charset_validator.rb
277
278
  - lib/kirico/validators/sjis_bytesize_validator.rb
279
+ - lib/kirico/validators/space_divider_validator.rb
278
280
  - lib/kirico/version.rb
279
281
  homepage: https://github.com/kufu/kirico
280
282
  licenses: