worlddb 0.2.2 → 0.3.0

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.
Files changed (84) hide show
  1. data/Manifest.txt +43 -32
  2. data/db/africa/countries.txt +10 -0
  3. data/db/america/br/cities.txt +7 -0
  4. data/db/america/br/regions.txt +27 -0
  5. data/db/america/ca/cities.txt +7 -0
  6. data/db/america/ca/regions.txt +10 -0
  7. data/db/america/countries.motor.yml +25 -0
  8. data/db/america/countries.txt +34 -0
  9. data/db/america/mx/cities.txt +15 -0
  10. data/db/america/us/cities.txt +16 -0
  11. data/db/america/us/regions.txt +10 -0
  12. data/db/america/ve/cities.txt +358 -0
  13. data/db/america/ve/regions.txt +46 -0
  14. data/db/asia/countries.txt +14 -0
  15. data/db/asia/jp/{cities.rb → cities.txt} +0 -0
  16. data/db/europe/at/cities.txt +32 -0
  17. data/db/europe/at/regions.txt +17 -0
  18. data/db/europe/be/cities.txt +1 -0
  19. data/db/europe/by/cities.txt +1 -0
  20. data/db/europe/ch/cities.txt +1 -0
  21. data/db/europe/countries.txt +65 -0
  22. data/db/europe/cy/cities.txt +1 -0
  23. data/db/europe/de/cities.txt +18 -0
  24. data/db/europe/de/regions.txt +16 -0
  25. data/db/europe/dk/cities.txt +1 -0
  26. data/db/europe/en/cities.txt +13 -0
  27. data/db/europe/es/cities.txt +5 -0
  28. data/db/europe/fr/cities.txt +4 -0
  29. data/db/europe/gr/cities.txt +1 -0
  30. data/db/europe/hr/cities.txt +1 -0
  31. data/db/europe/it/cities.txt +4 -0
  32. data/db/europe/nl/cities.txt +2 -0
  33. data/db/europe/pt/cities.txt +3 -0
  34. data/db/europe/ro/cities.txt +1 -0
  35. data/db/europe/ru/cities.txt +2 -0
  36. data/db/europe/sc/cities.txt +1 -0
  37. data/db/europe/tr/cities.txt +1 -0
  38. data/db/europe/ua/cities.txt +3 -0
  39. data/db/oceania/au/cities.txt +2 -0
  40. data/db/oceania/countries.txt +5 -0
  41. data/db/tags.yml +13 -0
  42. data/lib/worlddb.rb +6 -1
  43. data/lib/worlddb/cli/opts.rb +37 -0
  44. data/lib/worlddb/cli/runner.rb +29 -11
  45. data/lib/worlddb/models/city.rb +4 -0
  46. data/lib/worlddb/models/country.rb +3 -0
  47. data/lib/worlddb/models/region.rb +4 -0
  48. data/lib/worlddb/models/tag.rb +15 -0
  49. data/lib/worlddb/models/tagging.rb +12 -0
  50. data/lib/worlddb/reader.rb +211 -0
  51. data/lib/worlddb/schema.rb +17 -0
  52. data/lib/worlddb/version.rb +2 -1
  53. metadata +85 -36
  54. data/db/africa/countries.rb +0 -19
  55. data/db/america/ca/cities.rb +0 -31
  56. data/db/america/countries.rb +0 -44
  57. data/db/america/mx/cities.rb +0 -23
  58. data/db/america/us/cities.rb +0 -38
  59. data/db/america/ve/cities.rb +0 -2
  60. data/db/asia/countries.rb +0 -22
  61. data/db/europe/at/cities.rb +0 -70
  62. data/db/europe/be/cities.rb +0 -10
  63. data/db/europe/by/cities.rb +0 -9
  64. data/db/europe/ch/cities.rb +0 -9
  65. data/db/europe/countries.rb +0 -73
  66. data/db/europe/cy/cities.rb +0 -11
  67. data/db/europe/de/cities.rb +0 -51
  68. data/db/europe/dk/cities.rb +0 -9
  69. data/db/europe/en/cities.rb +0 -22
  70. data/db/europe/es/cities.rb +0 -13
  71. data/db/europe/fr/cities.rb +0 -12
  72. data/db/europe/gr/cities.rb +0 -9
  73. data/db/europe/hr/cities.rb +0 -9
  74. data/db/europe/it/cities.rb +0 -11
  75. data/db/europe/nl/cities.rb +0 -11
  76. data/db/europe/pt/cities.rb +0 -11
  77. data/db/europe/ro/cities.rb +0 -9
  78. data/db/europe/ru/cities.rb +0 -11
  79. data/db/europe/sc/cities.rb +0 -10
  80. data/db/europe/tr/cities.rb +0 -9
  81. data/db/europe/ua/cities.rb +0 -11
  82. data/db/oceania/au/cities.rb +0 -2
  83. data/db/oceania/countries.rb +0 -14
  84. data/db/tags.rb +0 -8
@@ -0,0 +1,46 @@
1
+ #-------------------------------------------------------------------------------
2
+ # Country: Venezuela
3
+ # Sources:
4
+ # - http://es.wikipedia.org/wiki/Organizaci%C3%B3n_territorial_de_Venezuela
5
+ #-------------------------------------------------------------------------------
6
+
7
+
8
+ #-------------------------------------------------------------------------------
9
+ # Table: regions_ve
10
+ # Note : In Venezuela, the political-territorial division of each region is
11
+ # called "Federal Entity" or "State". Each of these states is at the same
12
+ # time divided into several areas called "Municipalities". The list of
13
+ # cities in this table corresponds to the capitals of each of these
14
+ # municipalities.
15
+ # Population data were not added because the information shown on
16
+ # Wikipedia is outdated. Currently being revised 2011 Census data on the
17
+ # website of the National Statistics Institute
18
+ # http://www.ine.gov.ve/CENSO2011/index.htm
19
+ #-------------------------------------------------------------------------------
20
+
21
+ am, Amazonas
22
+ an, Anzoátegui
23
+ ap, Apure
24
+ ar, Aragua
25
+ ba, Barinas
26
+ bo, Bolívar
27
+ ca, Carabobo
28
+ co, Cojedes
29
+ da, Delta Amacuro
30
+ dc, Distrito Capital
31
+ fa, Falcón
32
+ gu, Guárico
33
+ la, Lara
34
+ me, Mérida
35
+ mi, Miranda
36
+ mo, Monagas
37
+ ne, Nueva Esparta
38
+ po, Portuguesa
39
+ su, Sucre
40
+ ta, Táchira
41
+ tr, Trujillo
42
+ va, Vargas
43
+ ya, Yaracuy
44
+ zu, Zulia
45
+
46
+
@@ -0,0 +1,14 @@
1
+ ##################################
2
+ ### asia (includes middle east)
3
+ ##
4
+
5
+ ## NB: uefa country kazakhstan is listed here
6
+ ## NB: australia is listed in oceania (w/ australia)
7
+
8
+
9
+ jp, Japan, JPN
10
+ kp, North Korea, PRK
11
+ kr, South Korea, KOR
12
+ in, India, IND
13
+ kz, Kazakhstan, KAZ, uefa
14
+
File without changes
@@ -0,0 +1,32 @@
1
+ wien, Wien|Vienna, region:wien, 1664146
2
+ stpoelten, St. Pölten, region:noe, 51360
3
+ wrneustadt, Wiener Neustadt|Wr. Neustadt, region:noe, 39940
4
+ moedling, Mödling|Moedling, region:noe, 20649
5
+ horn, Horn, region:noe, 6411, # < 10000 pop
6
+
7
+ linz, Linz, region:ooe, 188894
8
+ wels, Wels, region:ooe, 58623
9
+ steyr, Steyr, region:ooe, 38979
10
+ ried, Ried im Innkreis, region:ooe, 11585
11
+
12
+ eisenstadt, Eisenstadt, region:bgld, 12367
13
+ mattersburg, Mattersburg, region:bgld, 6256, # < 10000 pop
14
+
15
+ graz, Graz, region:stmk, 247698
16
+ kapfenberg, Kapfenberg, region:stmk, 21928
17
+ hartberg, Hartberg, region:stmk, 6547, # < 10000 pop
18
+
19
+ salzburg, Salzburg, region:sbg, 149018
20
+ groedig, Grödig, region:sbg, 6638, # < 10000 pop
21
+
22
+ klagenfurt, Klagenfurt, region:ktn, 92397
23
+ villach, Villach, region:ktn, 58480
24
+ wolfsberg, Wolfsberg, region:ktn, 25361
25
+
26
+ innsbruck, Innsbruck, region:tirol, 117693
27
+
28
+ dornbirn, Dornbirn, region:vbg, 44243
29
+ feldkirch, Feldkirch, region:vbg, 30093
30
+ bregenz, Bregenz, region:vbg, 27148
31
+ lustenau, Lustenau, region:vbg, 20606
32
+ altach, Altach, region:vbg, 5704, # < 10000 pop
@@ -0,0 +1,17 @@
1
+ #########
2
+ # sources:
3
+ # http://en.wikipedia.org/wiki/List_of_cities_and_towns_in_Austria
4
+ # http://en.wikipedia.org/wiki/List_of_cities_in_Austria_over_5,000_population_(2001_census)
5
+
6
+
7
+ ## 9 Bundeslaender
8
+
9
+ wien, Wien
10
+ noe, NÖ|Niederösterreich
11
+ ooe, OÖ|Oberösterreich
12
+ bgld, Bgld.|Burgenland
13
+ stmk, Stmk.|Steiermark
14
+ sbg, Sbg.|Salzburg
15
+ ktn, Ktn.|Kärnten
16
+ tirol, Tirol|Tirol
17
+ vbg, Vbg.|Vorarlberg
@@ -0,0 +1 @@
1
+ brussel, Brüssel|Brussel|Bruxelles|Brussels, # de|nl|fr|en - RCA Anderlecht
@@ -0,0 +1 @@
1
+ borisov, Borissow|Borisov|Barysaw
@@ -0,0 +1 @@
1
+ basel, Basel
@@ -0,0 +1,65 @@
1
+ ####################
2
+ ### europe
3
+
4
+
5
+ ## NB:
6
+ #
7
+ # countries also include:
8
+ # england (en), scotland (sc)
9
+ #
10
+ # also turkey, russia, georiga, etc.
11
+ # note: the uefa country kazachstan is listed in asia
12
+
13
+
14
+ ## NB: for keys use internet domain/iso two letter code
15
+ #
16
+ # more info about iso country codes:
17
+ # -> http://en.wikipedia.org/wiki/ISO_3166-1
18
+ # two letter codes -> http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
19
+ # three letter codes -> http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
20
+ #
21
+ # for three letter codes use fifa code or iso code
22
+ # - fifa three letter country codes
23
+ # -> http://en.wikipedia.org/wiki/List_of_FIFA_country_codes
24
+ # -> differences (fifa,ioc,iso) -> http://en.wikipedia.org/wiki/Comparison_of_IOC,_FIFA,_and_ISO_3166_country_codes
25
+
26
+
27
+ ad, Andorra, AND
28
+ al, Albania, ALB
29
+ am, Armenia, ARM
30
+ at, Austria, AUT, europe|uefa|eu|un
31
+ be, Belgium, BEL, europe|uefa|eu|un|benelux
32
+ bg, Bulgaria, BUL, # NB: ISO (BGR) <> FIFA (BUL)
33
+ by, Belarus, BLR
34
+ ch, Switzerland, SUI, europe|uefa|un, # NB: ISO (CHE) <> FIFA (SUI)
35
+ cy, Cyprus, CYP
36
+ cz, Czech Republic, CZE
37
+ de, Germany, GER, # NB: ISO (DEU) <> FIFA (GER)
38
+ dk, Denmark, DEN, # NB: ISO (DNK) <> FIFA (DEN)
39
+ en, England, ENG, # NB: FIFA (ENG); not a valid iso country n internet domain / its uk - what to use - anything better?
40
+ es, Spain, ESP
41
+ fi, Finland, FIN
42
+ fo, Faroe Islands, FRO
43
+ fr, France, FRA
44
+ ge, Georgia, GEO
45
+ gr, Greece, GRE, # NB: ISO (GRC) <> FIFA (GRE)
46
+ hr, Croatia, CRO, # NB: ISO (HRV) <> FIFA (CRO); local name: Hrvatska
47
+ hu, Hungary, HUN
48
+ ie, Irland, IRL
49
+ it, Italy, ITA
50
+ mt, Malta, MLT
51
+ nl, Netherlands, NED, # NB: ISO (NLD) <> FIFA (NED)
52
+ pl, Poland, POL
53
+ pt, Portugal, POR, # NB: ISO (PRT) <> FIFA (POR)
54
+ ro, Romania, ROU
55
+ rs, Serbia, SRB
56
+ ru, Russia, RUS
57
+ sc, Scotland, SCO, # NB: FIFA (SCO); not a valid iso country/internet domain - its uk - what to use - anything better?
58
+ se, Sweden, SWE
59
+ si, Slovenia, SVN
60
+ sk, Slovakia, SVK
61
+ tr, Turkey, TUR
62
+ ua, Ukraine, UKR
63
+ mk, Macedonia, MKD
64
+ no, Norway, NOR
65
+ is, Iceland, ISL
@@ -0,0 +1 @@
1
+ nikosia, Nikosia|Nicosia
@@ -0,0 +1,18 @@
1
+ muenchen, München, region:by
2
+ nuernberg, Nürnberg, region:by
3
+ augsburg, Augsburg, region:by
4
+ fuerth, Fürth, region:by
5
+ stuttgart, Stuttgart, region:bw
6
+ hoffenheim, Hoffenheim, region:bw
7
+ freiburg, Freiburg, region:bw
8
+ hannover, Hannover, region:ni
9
+ wolfsburg, Wolfsburg, region:ni
10
+ gelsenkirchen, Gelsenkirchen, region:nw
11
+ dortmund, Dortmund, region:nw
12
+ leverkusen, Leverkusen, region:nw
13
+ duesseldorf, Düsseldorf, region:nw
14
+ mgladbach, Mönchengladbach|Mgladbach, region:nw
15
+ frankfurt, Frankfurt, region:he
16
+ mainz, Mainz, region:rp
17
+ hamburg, Hamburg, region:hh
18
+ bremen, Bremen, region:hb
@@ -0,0 +1,16 @@
1
+ bw, Baden-Württemberg
2
+ by, Bayern
3
+ be, Berlin
4
+ bb, Brandenburg
5
+ hb, Bremen
6
+ hh, Hamburg
7
+ he, Hessen
8
+ mv, Mecklenburg-Vorpommern
9
+ ni, Niedersachsen
10
+ nw, Nordrhein-Westfalen
11
+ rp, Rheinland-Pfalz
12
+ sl, Saarland
13
+ sn, Sachsen
14
+ st, Sachsen-Anhalt
15
+ sh, Schleswig-Holstein
16
+ th, Thüringen
@@ -0,0 +1 @@
1
+ farum, Farum
@@ -0,0 +1,13 @@
1
+ manchester, Manchester
2
+ london, London
3
+ liverpool, Liverpool
4
+ birmingham, Birmingham, # e.g.Aston Villa
5
+ westbrom, West Bromwich
6
+ newcastle, Newcastle upon Tyne
7
+ stoke, Stoke-on-Trent
8
+ sunderland, Sunderland
9
+ wigan, Wigan
10
+ southampton, Southampton
11
+ reading, Reading
12
+ norwich, Norwich
13
+ swansea, Swansea
@@ -0,0 +1,5 @@
1
+ bilbao, Bilbao
2
+ valencia, Valencia
3
+ barcelona, Barcelona
4
+ madrid, Madrid
5
+ malaga, Málaga
@@ -0,0 +1,4 @@
1
+ lille, Lille
2
+ paris, Paris
3
+ marseille, Marseille
4
+ montpellier, Montpellier
@@ -0,0 +1 @@
1
+ piraeus, Piräus|Piraeus
@@ -0,0 +1 @@
1
+ zagreb, Zagreb
@@ -0,0 +1,4 @@
1
+ turin, Turin
2
+ milano, Mailand|Milano
3
+ napoli, Neapel|Napoli
4
+
@@ -0,0 +1,2 @@
1
+ amsterdam, Amsterdam
2
+ alkmaar, Alkmaar ## region: North Holland
@@ -0,0 +1,3 @@
1
+ porto, Porto
2
+ braga, Braga
3
+ lisboa, Lissabon|Lisboa
@@ -0,0 +1 @@
1
+ cluj, Cluj
@@ -0,0 +1,2 @@
1
+ moskva, Moskau|Moskva
2
+ stpetersburg, St. Petersburg
@@ -0,0 +1 @@
1
+ glasgow, Glasgow
@@ -0,0 +1 @@
1
+ istanbul, Istanbul
@@ -0,0 +1,3 @@
1
+ kiev, Kiew|Kiev|Kyiv
2
+ donetsk, Donezk|Donetsk
3
+ kharkov, Kharkiv|Kharkov
@@ -0,0 +1,2 @@
1
+
2
+ ## add australian regions and cities here
@@ -0,0 +1,5 @@
1
+ ###############################
2
+ ## australia & oceania
3
+
4
+ au, Australia, AUS
5
+ nz, New Zealand, NZL
@@ -0,0 +1,13 @@
1
+
2
+ ## some tags
3
+
4
+ continents: europe, america, asia, africa, oceania
5
+ americas: north america, south america, central america, caribbean islands
6
+ orgs: un, eu, mercosur, nafta
7
+ football: uefa, afc, ofc, caf, csf, concacaf
8
+
9
+ europe: benelux,euro
10
+
11
+
12
+ # regions
13
+ brasil: s|South,se|Southeast,co|Centerwest,ne|Northeast,n|North
@@ -26,7 +26,10 @@ require 'worlddb/models/prop'
26
26
  require 'worlddb/models/country'
27
27
  require 'worlddb/models/region'
28
28
  require 'worlddb/models/city'
29
+ require 'worlddb/models/tag'
30
+ require 'worlddb/models/tagging'
29
31
  require 'worlddb/schema' # NB: requires worlddb/models (include WorldDB::Models)
32
+ require 'worlddb/reader'
30
33
  require 'worlddb/loader'
31
34
  require 'worlddb/version'
32
35
  require 'worlddb/cli/opts'
@@ -68,9 +71,11 @@ module WorldDB
68
71
  def run( args=[] )
69
72
  # for now delete all tables
70
73
 
71
- Country.delete_all
74
+ Tagging.delete_all
75
+ Tag.delete_all
72
76
  City.delete_all
73
77
  Region.delete_all
78
+ Country.delete_all
74
79
  Prop.delete_all
75
80
  end
76
81
 
@@ -2,6 +2,43 @@ module WorldDB
2
2
 
3
3
  class Opts
4
4
 
5
+ def country=(value)
6
+ @country = value
7
+ end
8
+
9
+ def country
10
+ @country # NB: option has no default; return nil ## || '.'
11
+ end
12
+
13
+
14
+ def countries=(boolean)
15
+ @countries = boolean
16
+ end
17
+
18
+ def countries?
19
+ return false if @countries.nil? # default countries flag is false
20
+ @countries == true
21
+ end
22
+
23
+ def regions=(boolean)
24
+ @regions = boolean
25
+ end
26
+
27
+ def regions?
28
+ return false if @regions.nil? # default regions flag is false
29
+ @regions == true
30
+ end
31
+
32
+ def cities=(boolean)
33
+ @cities = boolean
34
+ end
35
+
36
+ def cities?
37
+ return false if @cities.nil? # default cities flag is false
38
+ @cities == true
39
+ end
40
+
41
+
5
42
  def create=(boolean)
6
43
  @create = boolean
7
44
  end
@@ -20,15 +20,26 @@ class Runner
20
20
 
21
21
  cmd.banner = "Usage: worlddb [options]"
22
22
 
23
- ## todo: change to different flag?? use -c/--config ???
24
- cmd.on( '-c', '--create', 'Create DB Schema' ) { opts.create = true }
23
+ ## NB: reserve -c for use with -c/--config
24
+ cmd.on( '--create', 'Create DB schema' ) { opts.create = true }
25
25
 
26
- cmd.on( '--delete', 'Delete all records' ) { opts.delete = true }
26
+ ### todo: in future allow multiple search path??
27
+ cmd.on( '-i', '--include PATH', "Data path (default is #{opts.data_path})" ) { |path| opts.data_path = path }
28
+
29
+ cmd.on( '--country KEY', "Default country for regions 'n' cities" ) { |key| opts.country = key; }
30
+
31
+ ## todo: add (generic) alias -t/--type cities for --cities
32
+ ## -t/--type regions for --regions
33
+ ## -t/--type countries for --countries --why? why not?
27
34
 
28
- cmd.on( '--load', 'Use Loader for Builtin World Data' ) { opts.load = true }
35
+ cmd.on( '--countries', 'Use country plain text fixture reader' ) { opts.countries = true }
36
+ cmd.on( '--regions', 'Use regions plain text fixture reader' ) { opts.regions = true }
37
+ cmd.on( '--cities', 'Use cities plain text fixture reader' ) { opts.cities = true }
38
+
39
+ ## todo: change to --builtin?? more clear why? why not?
40
+ cmd.on( '--load', 'Use loader for builtin world data' ) { opts.load = true }
29
41
 
30
- ### todo: in future allow multiple search path??
31
- cmd.on( '-i', '--include PATH', "Data Path (default is #{opts.data_path})" ) { |path| opts.data_path = path }
42
+ cmd.on( '--delete', 'Delete all records' ) { opts.delete = true }
32
43
 
33
44
  cmd.on( '-v', '--version', "Show version" ) do
34
45
  puts WorldDB.banner
@@ -50,8 +61,8 @@ worlddb - world.db command line tool, version #{VERSION}
50
61
  #{cmd.help}
51
62
 
52
63
  Examples:
53
- worlddb at/cities # import austrian regions n cities
54
- worlddb -c # create database schema
64
+ worlddb at/cities # import austrian cities
65
+ worlddb --create # create database schema
55
66
 
56
67
  More Examples:
57
68
  worlddb # show stats (table counts, table props)
@@ -71,8 +82,8 @@ EOS
71
82
  puts "working directory: #{Dir.pwd}"
72
83
 
73
84
  db_config = {
74
- :adapter => 'sqlite3',
75
- :database => "#{opts.output_path}/world.db"
85
+ adapter: 'sqlite3',
86
+ database: "#{opts.output_path}/world.db"
76
87
  }
77
88
 
78
89
  puts "Connecting to db using settings: "
@@ -88,7 +99,12 @@ EOS
88
99
  WorldDB.delete!
89
100
  end
90
101
 
91
- Loader.new( logger ).run( opts, args ) # load ruby fixtures
102
+
103
+ if opts.countries? || opts.regions? || opts.cities?
104
+ Reader.new( logger ).run( opts, args ) # load/read plain text country/region/city fixtures
105
+ else
106
+ Loader.new( logger ).run( opts, args ) # load ruby fixtures
107
+ end
92
108
 
93
109
  dump_stats
94
110
  dump_props
@@ -104,6 +120,8 @@ EOS
104
120
  puts " #{Country.count} countries"
105
121
  puts " #{Region.count} regions"
106
122
  puts " #{City.count} cities"
123
+ puts " #{Tag.count} tags"
124
+ puts " #{Tagging.count} taggings"
107
125
  end
108
126
 
109
127