class Valvat::Checksum::ES
Constants
- CIF_MUST_BE_A_LETTER_EXP
- CIF_MUST_BE_A_NUMBER_EXP
- GIVEN_CD_IS_A_LETTER_EXP
- LEGAL_PERSON_CHARS
- LEGAL_PERSON_EXP
- NATURAL_PERSON_CHARS
- NATURAL_PERSON_EXP
- NIE_DIGIT_BY_LETTER
- SPECIAL_NIF_EXP
Public Instance Methods
validate()
click to toggle source
# File lib/valvat/checksum/es.rb, line 16 def validate passes_special_validations? && possible_check_digits.include?(given_check_digit) end
Private Instance Methods
cd_can_be_a_letter?()
click to toggle source
# File lib/valvat/checksum/es.rb, line 73 def cd_can_be_a_letter? vat.to_s_wo_country !~ CIF_MUST_BE_A_NUMBER_EXP end
cd_can_be_a_num?()
click to toggle source
# File lib/valvat/checksum/es.rb, line 77 def cd_can_be_a_num? vat.to_s_wo_country !~ CIF_MUST_BE_A_LETTER_EXP end
given_cd_is_a_letter?()
click to toggle source
# File lib/valvat/checksum/es.rb, line 81 def given_cd_is_a_letter? !!(vat.to_s_wo_country =~ GIVEN_CD_IS_A_LETTER_EXP) end
given_check_digit()
click to toggle source
Calls superclass method
Valvat::Checksum::Base#given_check_digit
# File lib/valvat/checksum/es.rb, line 32 def given_check_digit given_cd_is_a_letter? ? str_wo_country[-1] : super end
legal_foreign_person?()
click to toggle source
# File lib/valvat/checksum/es.rb, line 69 def legal_foreign_person? !!(vat.to_s_wo_country =~ FOREIGN_LEGAL_PERSON_EXP) end
natural_person?()
click to toggle source
# File lib/valvat/checksum/es.rb, line 65 def natural_person? !!(vat.to_s_wo_country =~ NATURAL_PERSON_EXP) end
passes_special_validations?()
click to toggle source
# File lib/valvat/checksum/es.rb, line 22 def passes_special_validations? !( # [KLM]: CD first two numerical digits must be between 01 and 56 (both inclusive) (vat.to_s_wo_country =~ SPECIAL_NIF_EXP && (vat.to_s_wo_country[1..2].to_i > 56 || vat.to_s_wo_country[1..2].to_i < 1)) || # Exceptions: X0000000T, 00000001R, 00000000T & 99999999R are invalid. %w[X0000000T 00000001R 00000000T 99999999R].include?(vat.to_s_wo_country) ) end
person?()
click to toggle source
# File lib/valvat/checksum/es.rb, line 61 def person? natural_person? || legal_foreign_person? end
possible_cd_natural_person()
click to toggle source
# File lib/valvat/checksum/es.rb, line 40 def possible_cd_natural_person letter = vat.to_s_wo_country[0] nie_digit = NIE_DIGIT_BY_LETTER.index(letter) [NATURAL_PERSON_CHARS["#{nie_digit}#{figures_str}".to_i.modulo(23)]] end
possible_cds_legal_person()
click to toggle source
# File lib/valvat/checksum/es.rb, line 46 def possible_cds_legal_person chk = 10 - sum_of_figures_for_at_es_it_se(reverse_ints: true).modulo(10) possible_check_digits = [] possible_check_digits << LEGAL_PERSON_CHARS[chk] if cd_can_be_a_letter? if cd_can_be_a_num? possible_check_digits << (chk == 10 ? 0 : chk) end possible_check_digits end
possible_check_digits()
click to toggle source
# File lib/valvat/checksum/es.rb, line 36 def possible_check_digits natural_person? ? possible_cd_natural_person : possible_cds_legal_person end
str_wo_country()
click to toggle source
Calls superclass method
Valvat::Checksum::Base#str_wo_country
# File lib/valvat/checksum/es.rb, line 56 def str_wo_country str = super str[0] =~ /\d/ ? str : str[1..] end