Module: CodiceFiscale::Helpers
- Included in:
- FiscalCode
- Defined in:
- lib/codice_fiscale/helpers.rb
Instance Method Summary collapse
- #consonants(string) ⇒ Object
- #first_three_consonants(string) ⇒ Object
- #first_three_consonants_than_vowels(string) ⇒ Object
- #first_three_vowels(string) ⇒ Object
- #multiset_intersection(array_a, array_b) ⇒ Object
- #truncate_and_right_pad_with_three_x(string) ⇒ Object
Instance Method Details
#consonants(string) ⇒ Object
8 9 10 |
# File 'lib/codice_fiscale/helpers.rb', line 8 def consonants string multiset_intersection(string.chars, Alphabet.consonants).join end |
#first_three_consonants(string) ⇒ Object
12 13 14 |
# File 'lib/codice_fiscale/helpers.rb', line 12 def first_three_consonants string multiset_intersection(string.chars, Alphabet.consonants)[0..2].join end |
#first_three_consonants_than_vowels(string) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/codice_fiscale/helpers.rb', line 24 def first_three_consonants_than_vowels string upcase_string = string.upcase code = first_three_consonants upcase_string code << first_three_vowels(upcase_string) truncate_and_right_pad_with_three_x code end |
#first_three_vowels(string) ⇒ Object
16 17 18 |
# File 'lib/codice_fiscale/helpers.rb', line 16 def first_three_vowels string multiset_intersection(string.chars, Alphabet.vowels)[0..2].join end |
#multiset_intersection(array_a, array_b) ⇒ Object
4 5 6 |
# File 'lib/codice_fiscale/helpers.rb', line 4 def multiset_intersection array_a, array_b array_a.select { |letter| array_b.include? letter } end |
#truncate_and_right_pad_with_three_x(string) ⇒ Object
20 21 22 |
# File 'lib/codice_fiscale/helpers.rb', line 20 def truncate_and_right_pad_with_three_x string string[0..2].ljust 3, 'X' end |