mext_school_code_validator 1.0.0 → 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 +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/lib/mext_school_code_validator.rb +7 -6
- data/mext_school_code_validator.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f70445a3ee176d53b7a1cd028f1b566468558fac9444906ca848a5227e6dfe
|
4
|
+
data.tar.gz: 7e4038be9a335747fd2af058409cd7d3127bcd44299885d51d0941e832938e66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b431998bf64b4362f40a376ff59ef12dc1d4d9c08f8a0f28af5d0c734d7ce949e5688cb69103610dc7d1d967fb29f590566125d4ff2aafb91922befe2dc13ec2
|
7
|
+
data.tar.gz: 73da5d785b9f5f5f773fc831cda245de4dcffe6f7be3c0f1f4b074b41199597ff0bf9691eb7cc107e0620926690df864f48a2903d815ff8e3fdff229798c4d91
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -10,27 +10,28 @@ class MextSchoolCodeValidator < ActiveModel::EachValidator
|
|
10
10
|
"A" => "01", "B" => "02", "C" => "03", "D" => "04", "E" => "05",
|
11
11
|
"F" => "06", "G" => "07", "H" => "08"
|
12
12
|
}.freeze
|
13
|
-
VALID_ORG_TYPE_REGEXP =
|
14
|
-
VALID_PREFECTURE_NO_REGEXP =
|
15
|
-
|
13
|
+
VALID_ORG_TYPE_REGEXP = /\A[123]\z/.freeze
|
14
|
+
VALID_PREFECTURE_NO_REGEXP = /\A(?:0[1-9]|(?:[1-3][0-9])|(?:4[0-7]))\z/.freeze
|
15
|
+
VALID_SCHOOL_NO_REGEXP = /\A[1-9][0-9]{6}\z/.freeze
|
16
|
+
VALID_SCHOOL_TYPE_REGEXP = /\A(?:A1|A2|B1|C1|C2|D1|D2|E1|F1|F2|G1|H1|H2)/.freeze
|
16
17
|
|
17
18
|
def validate_each(record, attribute, value) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
18
19
|
value = value.presence.to_s
|
19
20
|
|
20
21
|
if value.length != LENGTH
|
21
22
|
record.errors.add(attribute, (options[:message] || :wrong_length), count: LENGTH)
|
22
|
-
elsif !value.
|
23
|
+
elsif !value.match?(VALID_SCHOOL_TYPE_REGEXP)
|
23
24
|
school_type = value[0, 2]
|
24
25
|
message = (options[:message] || :mext_school_code_invalid_school_type)
|
25
26
|
record.errors.add(attribute, message, school_type: school_type)
|
26
|
-
elsif !value.
|
27
|
+
elsif !value[2, 2].match?(VALID_PREFECTURE_NO_REGEXP)
|
27
28
|
prefecture_no = value[2, 2]
|
28
29
|
message = (options[:message] || :mext_school_code_invalid_prefecture_no)
|
29
30
|
record.errors.add(attribute, message, prefecture_no: prefecture_no)
|
30
31
|
elsif !value[4].match?(VALID_ORG_TYPE_REGEXP)
|
31
32
|
message = (options[:message] || :mext_school_code_invalid_org_type)
|
32
33
|
record.errors.add(attribute, message, org_type: value[4])
|
33
|
-
elsif value[5]
|
34
|
+
elsif !value[5, 7].match?(VALID_SCHOOL_NO_REGEXP)
|
34
35
|
message = (options[:message] || :mext_school_code_invalid_school_no)
|
35
36
|
record.errors.add(attribute, message, school_no: value[5, 7])
|
36
37
|
elsif calculate_check_digit(value).to_s != value[-1]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mext_school_code_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seiei Miyagi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -54,8 +54,8 @@ licenses:
|
|
54
54
|
metadata:
|
55
55
|
allowed_push_host: https://rubygems.org/
|
56
56
|
homepage_uri: https://github.com/hanachin/mext_school_code_validator
|
57
|
-
source_code_uri: https://github.com/hanachin/mext_school_code_validator/blob/1.0.
|
58
|
-
changelog_uri: https://github.com/hanachin/mext_school_code_validator/blob/1.0.
|
57
|
+
source_code_uri: https://github.com/hanachin/mext_school_code_validator/blob/1.0.1
|
58
|
+
changelog_uri: https://github.com/hanachin/mext_school_code_validator/blob/1.0.1/CHANGELOG.md
|
59
59
|
rubygems_mfa_required: 'true'
|
60
60
|
post_install_message:
|
61
61
|
rdoc_options: []
|