Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/itax_code/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def encode_name
consonants = utils.extract_consonants chars
vowels = utils.extract_vowels chars

consonants = consonants.chars.values_at(0, 2..consonants.size).join if consonants.length > 3
consonants = (consonants[0] + consonants[2..-1]).to_s if consonants.length > 3

"#{consonants[0..2]}#{vowels[0..2]}XXX"[0..2].upcase
end
Expand Down
11 changes: 11 additions & 0 deletions test/itax_code/encoder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ class EncoderTest < Minitest::Test
).encode
end

test "#encode when name has 5 consonants skips the 2nd consonant" do
assert_equal "RSSVNT80A01F205L",
Encoder.new(
surname: "Rossi",
name: "Valentino",
gender: "M",
birthdate: "1980-01-01",
birthplace: "Milano"
).encode
end

test "#encode for foreign countries" do
assert_equal "BRRDRN70M41Z602D",
Encoder.new(
Expand Down
Loading