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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bb2979ca66626a64373e40d5dd8177dd9284b6d70e537898076083e2c7ef620
4
- data.tar.gz: 072c6128a8224182f309832de880a4527e9f4de2941f4e04b76acddea8ee4ade
3
+ metadata.gz: 54f70445a3ee176d53b7a1cd028f1b566468558fac9444906ca848a5227e6dfe
4
+ data.tar.gz: 7e4038be9a335747fd2af058409cd7d3127bcd44299885d51d0941e832938e66
5
5
  SHA512:
6
- metadata.gz: 1ef527f31d3d16e9c507dcf2d193e8e4078e31dabb2885f4a5dc97bc97730d7a8149f7da30668f38033d891b094db4a57c3fe4068c6141bd6fce7f6190d99eef
7
- data.tar.gz: 689219e9350821a1ba3065ac6c098488cc14def05bc700702a0c9372aed06a3c2541f5654e9b1fbe22f72fc13249cbf93f2ede54501b89f12bf3c00ce8666091
6
+ metadata.gz: b431998bf64b4362f40a376ff59ef12dc1d4d9c08f8a0f28af5d0c734d7ce949e5688cb69103610dc7d1d967fb29f590566125d4ff2aafb91922befe2dc13ec2
7
+ data.tar.gz: 73da5d785b9f5f5f773fc831cda245de4dcffe6f7be3c0f1f4b074b41199597ff0bf9691eb7cc107e0620926690df864f48a2903d815ff8e3fdff229798c4d91
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2023-03-30
3
+ ## [1.0.1] - 2023-03-31
4
+
5
+ - Fix school no validation
6
+
7
+ ## [1.0.0] - 2023-03-31
4
8
 
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mext_school_code_validator (1.0.0)
4
+ mext_school_code_validator (1.0.1)
5
5
  activemodel
6
6
 
7
7
  GEM
@@ -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 = /[123]/.freeze
14
- VALID_PREFECTURE_NO_REGEXP = /..(?:0[1-9]|(?:[1-3][0-9])|(?:4[0-7]))/.freeze
15
- VALID_SCHOOL_TYPE_REGEXP = /A1|A2|B1|C1|C2|D1|D2|E1|F1|F2|G1|H1|H2/.freeze
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.start_with?(VALID_SCHOOL_TYPE_REGEXP)
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.start_with?(VALID_PREFECTURE_NO_REGEXP)
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] == "0"
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]
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "mext_school_code_validator"
5
- spec.version = "1.0.0"
5
+ spec.version = "1.0.1"
6
6
  spec.authors = ["Seiei Miyagi"]
7
7
  spec.email = ["hanachin@gmail.com"]
8
8
 
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.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-30 00:00:00.000000000 Z
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.0
58
- changelog_uri: https://github.com/hanachin/mext_school_code_validator/blob/1.0.0/CHANGELOG.md
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: []