Repository navigation
Implement spec 3.1: interim numbers, get_date and options - #42
Merged
Merged
Conversation
Accept interim numbers (the letters TRSUWXJKLMN, counted as 1 in the Luhn check) behind the allow_interim_number option, and add is_interim and get_date. parse, the constructor and valid? take an options hash with allow_coordination_number and allow_interim_number. parse used to drop the options it was given. valid? still accepts the old include_coord flag as its second argument. The regex is now anchored, so input with leading or trailing characters is invalid. Errors are raised as Personnummer::Error, a RuntimeError.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements version 3.1 of the package specification (https://github.com/personnummer/meta#package-specification-v31). The package has been on spec 3 until now.
What 3.1 adds:
YYMMDD-Xnnnwith one of the lettersTRSUWXJKLMN. The letter counts as1in the Luhn check andformatkeeps it.is_interimtells them apart, the wayis_coorddoes for coordination numbers.get_date, which returns aDate. For coordination numbers the 60 is subtracted from the day.get_ageuses it.parse, the constructor andvalid?:allow_coordination_number(defaulttrue) andallow_interim_number(defaultfalse). Interim numbers are rejected unless the option is set, so no input that was invalid before is valid by default now.Also in this PR:
Personnummer.parsedropped the options it was given (Personnummer.new(personnummer, options={})). It passes them on now.Personnummer.valid?("xx8507099805yy")wastrue.Personnummer::Error. It inherits fromRuntimeError, so an existingrescue RuntimeErrorstill catches it.valid?still takes the old flag as its second argument, soPersonnummer.valid?(number, false)works as before.The interim tests generate the valid cases in
testdata/interim.jsonin the meta repo from the eleven letters, and the invalid one is written out. The existing tests are unchanged.I have only run the tests on Ruby 3.4. The version and
.meta.yamlare not changed here, that is for the release PR.