Module: CodiceFiscale::Codes
- Extended by:
- Codes
- Includes:
- Configurable
- Included in:
- Codes
- Defined in:
- lib/codice_fiscale/codes.rb
Constant Summary collapse
- ITALY =
'Italia'
- MONTH_CODES =
%w[A B C D E H L M P R S T]
- ODD_CODES =
{'0' => 1, '1' => 0, '2' => 5, '3' => 7, '4' => 9, '5' => 13, '6' => 15, '7' => 17, '8' => 19, '9' => 21, 'A' => 1, 'B' => 0, 'C' => 5, 'D' => 7, 'E' => 9, 'F' => 13, 'G' => 15, 'H' => 17, 'I' => 19, 'J' => 21, 'K' => 2, 'L' => 4, 'M' => 18, 'N' => 20, 'O' => 11, 'P' => 3, 'Q' => 6, 'R' => 8, 'S' => 12, 'T' => 14, 'U' => 16, 'V' => 10, 'W' => 22, 'X' => 25, 'Y' => 24, 'Z' => 23}
- EVEN_CODES =
{'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24, 'Z' => 25}
- GENDERS =
[:male, :female]
Instance Method Summary collapse
- #city(city_name, province_code) ⇒ Object
- #control_character(number) ⇒ Object
- #country(country_name) ⇒ Object
- #even_character(character) ⇒ Object
- #italy?(country_name) ⇒ Boolean
- #month_letter(month_number) ⇒ Object
- #odd_character(character) ⇒ Object
Methods included from Configurable
Instance Method Details
#city(city_name, province_code) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/codice_fiscale/codes.rb', line 24 def city city_name, province_code return config.city_code.call(city_name, province_code) if config.city_code CSV.foreach config.city_codes_csv_path do |row| if city_name.casecmp(row[3].strip).zero? and province_code.casecmp(row[2].strip).zero? return row[0].strip.upcase end end nil end |
#control_character(number) ⇒ Object
50 51 52 |
# File 'lib/codice_fiscale/codes.rb', line 50 def control_character number Alphabet.letters[number] end |
#country(country_name) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/codice_fiscale/codes.rb', line 34 def country country_name return config.country_code.call(country_name) if config.country_code CSV.foreach config.country_codes_csv_path do |row| return row[3].strip.upcase if country_name.casecmp(row[2].strip).zero? end nil end |
#even_character(character) ⇒ Object
46 47 48 |
# File 'lib/codice_fiscale/codes.rb', line 46 def even_character character EVEN_CODES[character.upcase] end |
#italy?(country_name) ⇒ Boolean
54 55 56 |
# File 'lib/codice_fiscale/codes.rb', line 54 def italy? country_name ITALY.casecmp(country_name.strip).zero? end |
#month_letter(month_number) ⇒ Object
20 21 22 |
# File 'lib/codice_fiscale/codes.rb', line 20 def month_letter month_number month_number <= 0 ? nil : MONTH_CODES[month_number-1] end |
#odd_character(character) ⇒ Object
42 43 44 |
# File 'lib/codice_fiscale/codes.rb', line 42 def odd_character character ODD_CODES[character.upcase] end |