class NationalIdentificationNumber::Base
Public Class Methods
Source
# File lib/national_identification_number/base.rb, line 6 def initialize(number) @number = number repair validate end
Public Instance Methods
Source
# File lib/national_identification_number/base.rb, line 28 def ==(other) other.class == self.class && other&.to_s == to_s end
Source
# File lib/national_identification_number/base.rb, line 24 def age age_for_dob date end
Source
# File lib/national_identification_number/base.rb, line 20 def sanitize to_s if valid? end
Protected Instance Methods
Source
# File lib/national_identification_number/base.rb, line 35 def age_for_dob(dob) today = Time.now.utc.to_date return nil unless dob && today >= dob today.year - dob.year - ((today.month > dob.month || (today.month == dob.month && today.day >= dob.day)) ? 0 : 1) end
stackoverflow.com/questions/819263
Source
# File lib/national_identification_number/base.rb, line 41 def repair @number = @number.to_s.upcase.gsub(/\s/, '') end
Source
# File lib/national_identification_number/base.rb, line 45 def validate raise 'You need to implement at least this method in subclasses.' end