Class: Valvat::Checksum::IE
- Inherits:
-
Base
- Object
- Base
- Valvat::Checksum::IE
show all
- Defined in:
- lib/valvat/checksum/ie.rb
Constant Summary
collapse
- CHARS =
'WABCDEFGHIJKLMNOPQRSTUV'.split('')
Instance Attribute Summary
Attributes inherited from Base
#vat
Instance Method Summary
collapse
Methods inherited from Base
check_digit_length, #initialize, #validate
Instance Method Details
#check_digit ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/valvat/checksum/ie.rb', line 6
def check_digit
total = sum_figures_by do |fig, i|
fig * (i + 2)
end
total += ((CHARS.index(str_wo_country[8]) || 0) * 9) if str_wo_country.size == 9
total.modulo(23)
end
|
34
35
36
37
38
39
40
|
# File 'lib/valvat/checksum/ie.rb', line 34
def figures_str
if super.size == 8
super[0...-1]
else
super
end
end
|
#given_check_digit ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/valvat/checksum/ie.rb', line 16
def given_check_digit
if str_wo_country.size == 9
CHARS.index(str_wo_country[7])
else
CHARS.index(given_check_digit_str)
end
end
|
#str_wo_country ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/valvat/checksum/ie.rb', line 24
def str_wo_country
str = super
if str =~ /\A[0-9][A-Z][0-9]{5}[A-Z]\Z/
"0#{str[2..6]}#{str[0]}#{str[7]}"
else
str
end
end
|