Class: Helper::RrnHelper
- Inherits:
-
Object
- Object
- Helper::RrnHelper
- Defined in:
- lib/helper/rrn_helper.rb
Defined Under Namespace
Classes: RrnNotValid
Constant Summary collapse
- VALID_RRN =
"^(\\d{4}-){4}\\d{4}$".freeze
Class Method Summary collapse
Class Method Details
.hash_rrn(rrn) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/helper/rrn_helper.rb', line 24 def self.hash_rrn(rrn) rrn_array = rrn.split("-") rrn_array.unshift(rrn_array.last) rrn_array << rrn_array[1] Digest::SHA256.hexdigest rrn_array.join("-") end |
.normalise_rrn_format(rrn) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/helper/rrn_helper.rb', line 9 def self.normalise_rrn_format(rrn) # Strip surrounding whitespace rrn = rrn.strip # Remove all hyphens rrn = rrn.tr("-", "") raise RrnNotValid unless rrn.length == 20 # Add a hyphen every four characters to give desired RRN format rrn = rrn.scan(/.{1,4}/).join("-") raise RrnNotValid unless Regexp.new(VALID_RRN).match(rrn) rrn end |