localized_country_select 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module LocalizedCountrySelect
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -1,14 +1,15 @@
1
1
  require 'rubygems'
2
2
  require 'open-uri'
3
+ require 'active_support/inflector'
3
4
 
4
5
  # Rake task for importing country names from Unicode.org's CLDR repository
5
6
  # (http://www.unicode.org/cldr/data/charts/summary/root.html).
6
- #
7
- # It parses a HTML file from Unicode.org for given locale and saves the
7
+ #
8
+ # It parses a HTML file from Unicode.org for given locale and saves the
8
9
  # Rails' I18n hash in the plugin +locale+ directory
9
- #
10
+ #
10
11
  # Don't forget to restart the application when you add new locale to load it into Rails!
11
- #
12
+ #
12
13
  # == Parameters
13
14
  # LOCALE (required): Sets the locale to use. Output file name will include this.
14
15
  # FORMAT (optional): Output format, either 'rb' or 'yml'. Defaults to 'rb' if not specified.
@@ -17,7 +18,7 @@ require 'open-uri'
17
18
  # == Examples
18
19
  # rake import:country_select LOCALE=de
19
20
  # rake import:country_select LOCALE=pt-BR WEB_LOCALE=pt FORMAT=yml
20
- #
21
+ #
21
22
  # The code is deliberately procedural and simple, so it's easily
22
23
  # understandable by beginners as an introduction to Rake tasks power.
23
24
  # See https://github.com/svenfuchs/ruby-cldr for much more robust solution
@@ -32,9 +33,9 @@ namespace :import do
32
33
  puts "Error: Hpricot library required to use this task (import:country_select)"
33
34
  exit
34
35
  end
35
-
36
+
36
37
  # TODO : Implement locale import chooser from CLDR root via Highline
37
-
38
+
38
39
  # Setup variables
39
40
  locale = ENV['LOCALE']
40
41
  unless locale
@@ -62,16 +63,17 @@ namespace :import do
62
63
  puts "... parsing the HTML file"
63
64
  countries = []
64
65
  doc.search("//tr").each do |row|
65
- if row.search("td[@class='n']") &&
66
- row.search("td[@class='n']").inner_html =~ /^namesterritory$/ &&
67
- row.search("td[@class='g']").inner_html =~ /^[A-Z]{2}/
68
- code = row.search("td[@class='g']").inner_text
66
+ n = row.search("td[@class='n']")
67
+ g = row.search("td[@class='g']")
68
+ if n && n.inner_html =~ /NamesTerritories/ && g.inner_html =~ /^[A-Z]{2}/
69
+ code = g.inner_text
69
70
  code = code[-code.size, 2]
70
71
  name = row.search("td[@class='v']").inner_text
71
72
  countries << { :code => code.to_sym, :name => name.to_s }
72
- print " ... #{name}"
73
+ print " ... #{code}: #{name}"
73
74
  end
74
75
  end
76
+ puts "\n\n... imported countries: #{countries.count}"
75
77
 
76
78
 
77
79
  # ----- Prepare the output format ------------------------------------------
@@ -104,7 +106,7 @@ HEAD
104
106
  output << "\t\t\t:#{country[:code]} => \"#{country[:name]}\",\n"
105
107
  end
106
108
  output <<<<TAIL
107
- }
109
+ }
108
110
 
109
111
  }
110
112
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localized_country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2013-07-02 00:00:00.000000000 Z
18
+ date: 2013-10-26 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: actionpack
@@ -113,4 +113,3 @@ summary: Localized "country_select" helper with Rake task for downloading locale
113
113
  from Unicode.org's CLDR
114
114
  test_files:
115
115
  - test/localized_country_select_test.rb
116
- has_rdoc: