worlddb 0.6.5 → 0.6.6

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.
@@ -6,6 +6,8 @@ bin/worlddb
6
6
  db/africa/countries.txt
7
7
  db/africa/de.countries.yml
8
8
  db/africa/en.wikipedia.yml
9
+ db/africa/fifa.yml
10
+ db/africa/iso3.yml
9
11
  db/america/br/cities.txt
10
12
  db/america/br/regions.txt
11
13
  db/america/ca/cities.txt
@@ -86,6 +88,7 @@ lib/worlddb/models/region.rb
86
88
  lib/worlddb/models/tag.rb
87
89
  lib/worlddb/models/tagging.rb
88
90
  lib/worlddb/reader.rb
91
+ lib/worlddb/readers/hash_reader.rb
89
92
  lib/worlddb/readers/line_reader.rb
90
93
  lib/worlddb/readers/values_reader.rb
91
94
  lib/worlddb/schema.rb
@@ -0,0 +1,10 @@
1
+
2
+
3
+ ### some comments
4
+ ##
5
+
6
+ ao: ANG
7
+ bj: BEN
8
+ bw: BOT
9
+ bf: BFA
10
+ bi: BDI
@@ -0,0 +1,6 @@
1
+
2
+ ao: ANG
3
+ bj: BEN
4
+ bw: XOO
5
+ bf: XFA
6
+ bi: BDI
@@ -76,7 +76,7 @@ kz, Kazakhstan, KAZ, 2_724_900, 16_600_000, un|fifa|uefa|europe|central as
76
76
  sa, Saudi Arabia, KSA, 1_960_582, 27_136_977, un|fifa|middle_east|western_asia|arabian peninsula|g20
77
77
 
78
78
  il, Israel, ISR, 20_770, 7_653_600, un|fifa|middle_east|western_asia|fertile crescent
79
- pn, Palestine, PAL, 6_220, 4_260_636, middle_east|western_asia|fertile crescent
79
+ ps, Palestine, PAL, 6_220, 4_260_636, middle_east|western_asia|fertile crescent
80
80
 
81
81
  ## add to middle east?
82
82
 
@@ -10,10 +10,15 @@ md, Moldova, MDA, 33_846, 3_559_500, Chișinău, un|fifa
10
10
  sm, San Marino, SMR, 61, 32_404, City of San Marino, un|fifa
11
11
 
12
12
 
13
+
14
+
15
+
13
16
  ## NB:
14
17
  #
15
18
  # countries also include:
16
- # england (en), scotland (sc)
19
+ # england (en), scotland (ab for Alba (scotland in scotish gaelic) - sc (Seychellen),so,st,sl,sa,sn,sd all taken)
20
+ # use nd for northern ireland (ni (nicaragua),no, nr (naru) taken - anything better - anything common?)
21
+ # - use ul for ulster? better?
17
22
  #
18
23
  # also turkey, russia, georiga, etc.
19
24
  # note: the uefa country kazachstan is listed in asia
@@ -77,7 +82,7 @@ en, England, ENG, 130_395, 53_013_000, country:gb, fifa # NB: FIFA
77
82
  ## nb: sc -> seychellen, use different two letter code st?
78
83
  st, Scotland, SCO, 78_387, 5_254_800, country:gb, fifa # NB: FIFA (SCO); not a valid iso country/internet domain - its uk - what to use - anything better?
79
84
  wa, Wales, WAL, 20_779, 3_064_000, country:gb, fifa
80
-
85
+ nd, Northern Ireland, NIR, 13_843, 1_810_900, Belfast, country:gb, fifa
81
86
 
82
87
 
83
88
  fo, Faroe Islands, FRO, 1_399, 49_267, country:dk
@@ -95,6 +100,7 @@ mk, Macedonia, MKD, 25_713, 2_082_370, un|fifa
95
100
  no, Norway, NOR, 385_155, 4_993_300, un|fifa|schengen|uefa
96
101
  is, Iceland, ISL, 103_000, 318_452, un|fifa|schengen|uefa
97
102
 
103
+ va, Vatican City, VAT, 1, 836, Vatican City
98
104
 
99
105
  ## todo/fix: add missing countries
100
106
 
@@ -32,6 +32,7 @@ require 'worlddb/schema' # NB: requires worlddb/models (include WorldDB::M
32
32
  require 'worlddb/utils'
33
33
  require 'worlddb/readers/line_reader'
34
34
  require 'worlddb/readers/values_reader'
35
+ require 'worlddb/readers/hash_reader'
35
36
  require 'worlddb/reader'
36
37
  require 'worlddb/loader'
37
38
  require 'worlddb/cli/opts'
@@ -68,6 +69,8 @@ module WorldDB
68
69
  def self.fixtures # all builtin fixtures; helper for covenience
69
70
 
70
71
  ['africa/countries',
72
+ 'africa/fifa',
73
+ 'africa/iso3',
71
74
  'america/countries',
72
75
  'america/br/regions',
73
76
  'america/br/cities',
@@ -75,7 +75,14 @@ class Reader
75
75
  # load from gem (built-in)
76
76
 
77
77
  def load_builtin( name ) ## convenience helper (requires proper named files w/ convention)
78
- if name =~ /\/countries/
78
+
79
+ ## add motor, wikipedia, net, etc.
80
+
81
+ if name =~ /\/fifa/
82
+ load_fifa_builtin( name )
83
+ elsif name =~ /\/iso3/
84
+ load_iso3_builtin( name )
85
+ elsif name =~ /\/countries/
79
86
  load_countries_builtin( name )
80
87
  elsif name =~ /\/([a-z]{2})\/cities/
81
88
  load_cities_builtin( $1, name )
@@ -106,6 +113,59 @@ class Reader
106
113
  end
107
114
 
108
115
 
116
+ def load_iso3_builtin( name )
117
+ path = "#{WorldDB.root}/db/#{name}.yml"
118
+
119
+ puts "*** parsing data '#{name}' (#{path})..."
120
+
121
+ reader = HashReader.new( logger, path )
122
+
123
+ ### fix: use each on reader!!! move normalize into reader
124
+ reader.hash.each do |key_wild, value_wild|
125
+
126
+ # normalize
127
+ # - key n value as string (not symbols, bool? int? array?)
128
+ # - remove leading and trailing whitespace
129
+ key = key_wild.to_s.strip
130
+ value = value_wild.to_s.strip
131
+
132
+ puts ">>#{key}<< >>#{value}<<"
133
+
134
+ country = Country.find_by_key!( key )
135
+ country.iso3 = value
136
+ country.save!
137
+
138
+ end
139
+
140
+ Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
141
+ end
142
+
143
+ def load_fifa_builtin( name )
144
+ path = "#{WorldDB.root}/db/#{name}.yml"
145
+
146
+ puts "*** parsing data '#{name}' (#{path})..."
147
+
148
+ reader = HashReader.new( logger, path )
149
+
150
+ reader.hash.each do |key_wild, value_wild|
151
+
152
+ # normalize
153
+ key = key_wild.to_s.strip
154
+ value = value_wild.to_s.strip
155
+
156
+ puts ">>#{key}<< >>#{value}<<"
157
+
158
+ country = Country.find_by_key!( key )
159
+ country.fifa = value
160
+ country.save!
161
+
162
+ end
163
+
164
+ Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
165
+ end
166
+
167
+
168
+
109
169
  private
110
170
  def load_fixtures_with_include_path_for( clazz, name, include_path, more_values={} ) # load from file system
111
171
  path = "#{include_path}/#{name}.txt"
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ class HashReader
5
+
6
+ def initialize( logger=nil, path )
7
+ if logger.nil?
8
+ @logger = Logger.new(STDOUT)
9
+ @logger.level = Logger::INFO
10
+ else
11
+ @logger = logger
12
+ end
13
+
14
+ @path = path
15
+
16
+ ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
17
+ ## - see worlddb/utils.rb
18
+ @hash = YAML.load( File.read_utf8( @path ))
19
+ end
20
+
21
+ attr_reader :logger, :hash
22
+
23
+ end # class HashReader
@@ -24,9 +24,15 @@ create_table :countries do |t|
24
24
  t.timestamps
25
25
 
26
26
  # extras
27
- t.string :motor # optional auto motor (vehicle) licene plate
27
+ t.string :motor # optional auto motor (vehicle) licene plate
28
+ t.string :iso2 # optional iso two letter country code
29
+ t.string :iso3 # optional iso three letter country code
30
+ t.string :fifa # optional fifa country code
31
+ t.string :net # optional internet top level domain (tld)
32
+ t.string :wikipedia # optional wikipedia page name -- en.wikipedia.org/wiki/<name>
28
33
  end
29
34
 
35
+
30
36
  add_index :countries, :key, :unique => true
31
37
  add_index :countries, :code, :unique => true
32
38
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module WorldDB
3
- VERSION = '0.6.5'
3
+ VERSION = '0.6.6'
4
4
  end
5
5
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 5
10
- version: 0.6.5
9
+ - 6
10
+ version: 0.6.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-29 00:00:00 Z
18
+ date: 2012-11-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -136,6 +136,8 @@ files:
136
136
  - db/africa/countries.txt
137
137
  - db/africa/de.countries.yml
138
138
  - db/africa/en.wikipedia.yml
139
+ - db/africa/fifa.yml
140
+ - db/africa/iso3.yml
139
141
  - db/america/br/cities.txt
140
142
  - db/america/br/regions.txt
141
143
  - db/america/ca/cities.txt
@@ -216,6 +218,7 @@ files:
216
218
  - lib/worlddb/models/tag.rb
217
219
  - lib/worlddb/models/tagging.rb
218
220
  - lib/worlddb/reader.rb
221
+ - lib/worlddb/readers/hash_reader.rb
219
222
  - lib/worlddb/readers/line_reader.rb
220
223
  - lib/worlddb/readers/values_reader.rb
221
224
  - lib/worlddb/schema.rb