Class: IdPlease::ES::Validator
- Inherits:
-
Object
- Object
- IdPlease::ES::Validator
- Defined in:
- lib/id-please/countries/es.rb
Constant Summary collapse
- DNI_alphabet =
'TRWAGMYFPDXBNJZSQVHLCKE'
- REGEX =
{ dni: /^(\d{8})([#{DNI_alphabet}])$/, nie: /^([XYZ])(\d{7})([#{DNI_alphabet}])$/, cif: /^([ABCDEFGHJKLMNPQRSUVW])(\d{7})(\d)$/ }
Instance Method Summary collapse
- #check(id) ⇒ Object
-
#validate_cif(id) ⇒ Object
TODO.
- #validate_dni(id) ⇒ Object
- #validate_nie(id) ⇒ Object
Instance Method Details
#check(id) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/id-please/countries/es.rb', line 12 def check id REGEX.each do |k, v| return send("validate_#{k}", id.upcase) unless id.upcase.match(v).nil? end raise "Invalid ID" end |
#validate_cif(id) ⇒ Object
TODO
28 29 30 |
# File 'lib/id-please/countries/es.rb', line 28 def validate_cif id #TODO raise "TODO" end |
#validate_dni(id) ⇒ Object
20 21 22 |
# File 'lib/id-please/countries/es.rb', line 20 def validate_dni id DNI_alphabet[id[0..7].to_i % 23] == id[8] end |
#validate_nie(id) ⇒ Object
24 25 26 |
# File 'lib/id-please/countries/es.rb', line 24 def validate_nie id validate_dni("#{'XYZ'.index(id[0])}#{id[1..8]}") end |