lib/codice_fiscale/codes.rb in codice-fiscale-0.0.5 vs lib/codice_fiscale/codes.rb in codice-fiscale-0.0.6

- old
+ new

@@ -1,7 +1,8 @@ module CodiceFiscale module Codes + include Configurable extend self ITALY = 'Italia' MONTH_CODES = %w[A B C D E H L M P R S T] @@ -14,30 +15,28 @@ '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] - def config - CodiceFiscale.config - end - def month_letter month_number month_number <= 0 ? nil : MONTH_CODES[month_number-1] end 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) == 0 and province_code.casecmp(row[2].strip) == 0 + 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 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) == 0 + return row[3].strip.upcase if country_name.casecmp(row[2].strip).zero? end nil end def odd_character character @@ -46,14 +45,14 @@ def even_character character EVEN_CODES[character.upcase] end - def check_character number + def control_character number Alphabet.letters[number] end def italy? country_name - ITALY.casecmp(country_name.strip) == 0 + ITALY.casecmp(country_name.strip).zero? end end end \ No newline at end of file