Class: I18nCountryTranslations::ImportTwoLetterCodes
- Inherits:
-
Object
- Object
- I18nCountryTranslations::ImportTwoLetterCodes
- Defined in:
- lib/i18n_country_translations/import_two_letter_codes.rb
Instance Attribute Summary collapse
-
#locales ⇒ Object
readonly
Returns the value of attribute locales.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
Instance Method Summary collapse
-
#initialize(locales = nil) ⇒ ImportTwoLetterCodes
constructor
A new instance of ImportTwoLetterCodes.
- #process ⇒ Object
Constructor Details
#initialize(locales = nil) ⇒ ImportTwoLetterCodes
Returns a new instance of ImportTwoLetterCodes.
12 13 14 15 16 17 18 19 20 |
# File 'lib/i18n_country_translations/import_two_letter_codes.rb', line 12 def initialize(locales = nil) @locales = if locales [locales] else present_locales end @output_dir = file_location end |
Instance Attribute Details
#locales ⇒ Object (readonly)
Returns the value of attribute locales.
10 11 12 |
# File 'lib/i18n_country_translations/import_two_letter_codes.rb', line 10 def locales @locales end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
9 10 11 |
# File 'lib/i18n_country_translations/import_two_letter_codes.rb', line 9 def output_dir @output_dir end |
Instance Method Details
#process ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/i18n_country_translations/import_two_letter_codes.rb', line 22 def process @locales.each_with_index do |locale, index| # ----- Get the CLDR HTML -------------------------------------------------- begin doc = Nokogiri::HTML(open("http://www.unicode.org/cldr/charts/latest/summary/#{locale}.html")) rescue => e puts "[!] Invalid locale name '#{locale}'! Not found in CLDR (#{e})" return if index == @locales.length - 1 end # ----- Parse the HTML with Nokogiri ---------------------------------------- output = { locale => { "countries" => search_for_countries(doc) } } # ----- Write the parsed values into file --------------------------------- write_for(locale, output) end end |