Merge pull request #57 from internetee/story/109590460-setting-ident

Story/109590460 setting ident
This commit is contained in:
Timo Võhmar 2016-01-07 14:06:54 +02:00
commit 438b22f19d
2 changed files with 23 additions and 19 deletions

View file

@ -236,12 +236,16 @@ class Contact < ActiveRecord::Base
end
def ident_valid_format?
case ident_type
when 'priv'
case ident_country_code
when 'EE'
code = Isikukood.new(ident)
errors.add(:ident, :invalid_EE_identity_format) unless code.valid?
case ident_country_code
when 'EE'.freeze
case ident_type
when 'priv'.freeze
errors.add(:ident, :invalid_EE_identity_format) unless Isikukood.new(ident).valid?
when 'org'.freeze
# !%w(1 7 8 9).freeze.include?(ident.first) ||
if ident.size != 8 || !(ident =~/\A[0-9]{8}\z/)
errors.add(:ident, :invalid_EE_identity_format)
end
end
end
end