worlddb 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/Manifest.txt +73 -73
  2. data/Rakefile +8 -2
  3. data/{db → data}/africa/countries.txt +3 -1
  4. data/{db → data}/africa/de.countries.yml +0 -0
  5. data/{db → data}/africa/en.wikipedia.yml +0 -0
  6. data/{db → data}/africa/fifa.yml +0 -0
  7. data/{db → data}/africa/iso3.yml +0 -0
  8. data/{db → data}/america/br/cities.txt +0 -0
  9. data/{db → data}/america/br/regions.txt +0 -0
  10. data/{db → data}/america/ca/cities.txt +0 -0
  11. data/{db → data}/america/ca/regions.txt +0 -0
  12. data/{db → data}/america/countries.motor.yml +0 -0
  13. data/{db → data}/america/countries.txt +0 -0
  14. data/{db → data}/america/de.countries.yml +0 -0
  15. data/{db → data}/america/en.wikipedia.yml +0 -0
  16. data/{db → data}/america/es.countries.yml +0 -0
  17. data/{db → data}/america/mx/cities.txt +0 -0
  18. data/{db → data}/america/mx/regions.txt +0 -0
  19. data/{db → data}/america/us/cities.txt +0 -0
  20. data/{db → data}/america/us/regions.txt +0 -0
  21. data/{db → data}/america/ve/cities.txt +0 -0
  22. data/{db → data}/america/ve/regions.txt +0 -0
  23. data/{db → data}/asia/countries.txt +0 -0
  24. data/{db → data}/asia/de.countries.yml +0 -0
  25. data/{db → data}/asia/en.wikipedia.yml +0 -0
  26. data/{db → data}/asia/jp/cities.txt +0 -0
  27. data/{db → data}/europe/at/cities.txt +0 -0
  28. data/{db → data}/europe/at/regions.txt +0 -0
  29. data/{db → data}/europe/be/cities.txt +0 -0
  30. data/{db → data}/europe/be/regions.txt +0 -0
  31. data/{db → data}/europe/bg/cities.txt +0 -0
  32. data/{db → data}/europe/by/cities.txt +0 -0
  33. data/{db → data}/europe/ch/cities.txt +0 -0
  34. data/{db → data}/europe/countries.txt +2 -3
  35. data/{db → data}/europe/cy/cities.txt +0 -0
  36. data/{db → data}/europe/cz/cities.txt +0 -0
  37. data/{db → data}/europe/cz/regions.txt +0 -0
  38. data/{db → data}/europe/de/cities.txt +0 -0
  39. data/{db → data}/europe/de/regions.txt +0 -0
  40. data/{db → data}/europe/de.countries.yml +0 -0
  41. data/{db → data}/europe/dk/cities.txt +0 -0
  42. data/{db → data}/europe/ee/cities.txt +0 -0
  43. data/{db → data}/europe/en/cities.txt +0 -0
  44. data/{db → data}/europe/en/regions.txt +0 -0
  45. data/{db → data}/europe/en.wikipedia.yml +0 -0
  46. data/{db → data}/europe/es/cities.txt +0 -0
  47. data/{db → data}/europe/es/regions.txt +0 -0
  48. data/{db → data}/europe/es.countries.yml +0 -0
  49. data/{db → data}/europe/fi/cities.txt +0 -0
  50. data/{db → data}/europe/fr/cities.txt +0 -0
  51. data/{db → data}/europe/fr/regions.txt +0 -0
  52. data/{db → data}/europe/gr/cities.txt +0 -0
  53. data/{db → data}/europe/hr/cities.txt +0 -0
  54. data/{db → data}/europe/hu/cities.txt +0 -0
  55. data/{db → data}/europe/ie/cities.txt +0 -0
  56. data/{db → data}/europe/it/cities.txt +0 -0
  57. data/{db → data}/europe/lt/cities.txt +0 -0
  58. data/{db → data}/europe/lv/cities.txt +0 -0
  59. data/{db → data}/europe/nl/cities.txt +0 -0
  60. data/{db → data}/europe/no/cities.txt +0 -0
  61. data/{db → data}/europe/pl/cities.txt +0 -0
  62. data/{db → data}/europe/pt/cities.txt +0 -0
  63. data/{db → data}/europe/ro/cities.txt +0 -0
  64. data/{db → data}/europe/rs/cities.txt +0 -0
  65. data/{db → data}/europe/ru/cities.txt +0 -0
  66. data/{db → data}/europe/sc/cities.txt +0 -0
  67. data/{db → data}/europe/se/cities.txt +0 -0
  68. data/{db → data}/europe/tr/cities.txt +0 -0
  69. data/{db → data}/europe/ua/cities.txt +0 -0
  70. data/{db → data}/europe/wa/cities.txt +0 -0
  71. data/{db → data}/oceania/au/cities.txt +0 -0
  72. data/{db → data}/oceania/countries.txt +0 -0
  73. data/{db → data}/oceania/de.countries.yml +0 -0
  74. data/{db → data}/oceania/en.wikipedia.yml +0 -0
  75. data/{db → data}/tags.yml +0 -0
  76. data/lib/worlddb/loader.rb +1 -1
  77. data/lib/worlddb/models/city.rb +33 -13
  78. data/lib/worlddb/models/country.rb +17 -10
  79. data/lib/worlddb/models/tag.rb +4 -9
  80. data/lib/worlddb/reader.rb +56 -35
  81. data/lib/worlddb/schema.rb +10 -3
  82. data/lib/worlddb/version.rb +1 -1
  83. metadata +82 -139
data/Manifest.txt CHANGED
@@ -3,79 +3,79 @@ Manifest.txt
3
3
  README.markdown
4
4
  Rakefile
5
5
  bin/worlddb
6
- db/africa/countries.txt
7
- db/africa/de.countries.yml
8
- db/africa/en.wikipedia.yml
9
- db/africa/fifa.yml
10
- db/africa/iso3.yml
11
- db/america/br/cities.txt
12
- db/america/br/regions.txt
13
- db/america/ca/cities.txt
14
- db/america/ca/regions.txt
15
- db/america/countries.motor.yml
16
- db/america/countries.txt
17
- db/america/de.countries.yml
18
- db/america/en.wikipedia.yml
19
- db/america/es.countries.yml
20
- db/america/mx/cities.txt
21
- db/america/mx/regions.txt
22
- db/america/us/cities.txt
23
- db/america/us/regions.txt
24
- db/america/ve/cities.txt
25
- db/america/ve/regions.txt
26
- db/asia/countries.txt
27
- db/asia/de.countries.yml
28
- db/asia/en.wikipedia.yml
29
- db/asia/jp/cities.txt
30
- db/europe/at/cities.txt
31
- db/europe/at/regions.txt
32
- db/europe/be/cities.txt
33
- db/europe/be/regions.txt
34
- db/europe/bg/cities.txt
35
- db/europe/by/cities.txt
36
- db/europe/ch/cities.txt
37
- db/europe/countries.txt
38
- db/europe/cy/cities.txt
39
- db/europe/cz/cities.txt
40
- db/europe/cz/regions.txt
41
- db/europe/de.countries.yml
42
- db/europe/de/cities.txt
43
- db/europe/de/regions.txt
44
- db/europe/dk/cities.txt
45
- db/europe/ee/cities.txt
46
- db/europe/en.wikipedia.yml
47
- db/europe/en/cities.txt
48
- db/europe/en/regions.txt
49
- db/europe/es.countries.yml
50
- db/europe/es/cities.txt
51
- db/europe/es/regions.txt
52
- db/europe/fi/cities.txt
53
- db/europe/fr/cities.txt
54
- db/europe/fr/regions.txt
55
- db/europe/gr/cities.txt
56
- db/europe/hr/cities.txt
57
- db/europe/hu/cities.txt
58
- db/europe/ie/cities.txt
59
- db/europe/it/cities.txt
60
- db/europe/lt/cities.txt
61
- db/europe/lv/cities.txt
62
- db/europe/nl/cities.txt
63
- db/europe/no/cities.txt
64
- db/europe/pl/cities.txt
65
- db/europe/pt/cities.txt
66
- db/europe/ro/cities.txt
67
- db/europe/rs/cities.txt
68
- db/europe/ru/cities.txt
69
- db/europe/sc/cities.txt
70
- db/europe/se/cities.txt
71
- db/europe/tr/cities.txt
72
- db/europe/ua/cities.txt
73
- db/europe/wa/cities.txt
74
- db/oceania/au/cities.txt
75
- db/oceania/countries.txt
76
- db/oceania/de.countries.yml
77
- db/oceania/en.wikipedia.yml
78
- db/tags.yml
6
+ data/africa/countries.txt
7
+ data/africa/de.countries.yml
8
+ data/africa/en.wikipedia.yml
9
+ data/africa/fifa.yml
10
+ data/africa/iso3.yml
11
+ data/america/br/cities.txt
12
+ data/america/br/regions.txt
13
+ data/america/ca/cities.txt
14
+ data/america/ca/regions.txt
15
+ data/america/countries.motor.yml
16
+ data/america/countries.txt
17
+ data/america/de.countries.yml
18
+ data/america/en.wikipedia.yml
19
+ data/america/es.countries.yml
20
+ data/america/mx/cities.txt
21
+ data/america/mx/regions.txt
22
+ data/america/us/cities.txt
23
+ data/america/us/regions.txt
24
+ data/america/ve/cities.txt
25
+ data/america/ve/regions.txt
26
+ data/asia/countries.txt
27
+ data/asia/de.countries.yml
28
+ data/asia/en.wikipedia.yml
29
+ data/asia/jp/cities.txt
30
+ data/europe/at/cities.txt
31
+ data/europe/at/regions.txt
32
+ data/europe/be/cities.txt
33
+ data/europe/be/regions.txt
34
+ data/europe/bg/cities.txt
35
+ data/europe/by/cities.txt
36
+ data/europe/ch/cities.txt
37
+ data/europe/countries.txt
38
+ data/europe/cy/cities.txt
39
+ data/europe/cz/cities.txt
40
+ data/europe/cz/regions.txt
41
+ data/europe/de.countries.yml
42
+ data/europe/de/cities.txt
43
+ data/europe/de/regions.txt
44
+ data/europe/dk/cities.txt
45
+ data/europe/ee/cities.txt
46
+ data/europe/en.wikipedia.yml
47
+ data/europe/en/cities.txt
48
+ data/europe/en/regions.txt
49
+ data/europe/es.countries.yml
50
+ data/europe/es/cities.txt
51
+ data/europe/es/regions.txt
52
+ data/europe/fi/cities.txt
53
+ data/europe/fr/cities.txt
54
+ data/europe/fr/regions.txt
55
+ data/europe/gr/cities.txt
56
+ data/europe/hr/cities.txt
57
+ data/europe/hu/cities.txt
58
+ data/europe/ie/cities.txt
59
+ data/europe/it/cities.txt
60
+ data/europe/lt/cities.txt
61
+ data/europe/lv/cities.txt
62
+ data/europe/nl/cities.txt
63
+ data/europe/no/cities.txt
64
+ data/europe/pl/cities.txt
65
+ data/europe/pt/cities.txt
66
+ data/europe/ro/cities.txt
67
+ data/europe/rs/cities.txt
68
+ data/europe/ru/cities.txt
69
+ data/europe/sc/cities.txt
70
+ data/europe/se/cities.txt
71
+ data/europe/tr/cities.txt
72
+ data/europe/ua/cities.txt
73
+ data/europe/wa/cities.txt
74
+ data/oceania/au/cities.txt
75
+ data/oceania/countries.txt
76
+ data/oceania/de.countries.yml
77
+ data/oceania/en.wikipedia.yml
78
+ data/tags.yml
79
79
  lib/worlddb.rb
80
80
  lib/worlddb/cli/opts.rb
81
81
  lib/worlddb/cli/runner.rb
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'hoe'
2
2
  require './lib/worlddb/version.rb'
3
3
 
4
+ ## NB: plugin (hoe-manifest) not required; just used for future testing/development
5
+ Hoe::plugin :manifest # more options for manifests (in the future; not yet)
6
+
4
7
  Hoe.spec 'worlddb' do
5
8
 
6
9
  self.version = WorldDB::VERSION
@@ -14,12 +17,15 @@ Hoe.spec 'worlddb' do
14
17
  self.email = 'opensport@googlegroups.com'
15
18
 
16
19
  # switch extension to .markdown for gihub formatting
17
- self.readme_file = 'README.markdown'
18
- self.history_file = 'History.markdown'
20
+ # - auto-added from Manifest.txt (see define_spec in class Hoe)
21
+ # self.readme_file = 'README.markdown'
22
+ # self.history_file = 'History.markdown'
19
23
 
20
24
  self.extra_deps = [
21
25
  ['activerecord', '~> 3.2'] # NB: will include activesupport,etc.
22
26
  ### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
23
27
  ]
28
+
29
+ self.licenses = ['Public Domain']
24
30
 
25
31
  end
@@ -54,7 +54,9 @@ rw, Rwanda, RWA, 26_338, 11_689_696, Kigali, un|fifa
54
54
  st, São Tomé and Príncipe, STP, 1_001, 183_176, São Tomé, un|fifa
55
55
 
56
56
  sn, Senegal, SEN, 196_723, 12_855_153, Dakar, un|fifa
57
- sc, Seychelles, SEY, 451, 84_000, Victoria, un|fifa
57
+
58
+ ## NB: sc renamed to ey (sc used for Scottland)
59
+ ey, Seychelles, SEY, 451, 84_000, Victoria, un|fifa
58
60
  sl, Sierra Leone, SLE, 71_740, 5_485_998, Freetown, un|fifa
59
61
 
60
62
  so, Somalia, SOM, 637_657, 10_085_638, Mogadishu, un|fifa
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -16,7 +16,7 @@ sm, San Marino, SMR, 61, 32_404, City of San Marino, un|fifa
16
16
  ## NB:
17
17
  #
18
18
  # countries also include:
19
- # england (en), scotland (ab for Alba (scotland in scotish gaelic) - sc (Seychellen),so,st,sl,sa,sn,sd all taken)
19
+ # england (en), scotland (sc) - nb: Seychellen renamed from sc to ey
20
20
  # use nd for northern ireland (ni (nicaragua),no, nr (naru) taken - anything better - anything common?)
21
21
  # - use ul for ulster? better?
22
22
  #
@@ -79,8 +79,7 @@ hu, Hungary, HUN, 93_030, 9_979_000, supra:eu, un|fifa|eu|uefa|sche
79
79
  gb, Great Britain, GBR, 243_610, 63_047_162, supra:eu, un|eu|g8|g20
80
80
  en, England, ENG, 130_395, 53_013_000, country:gb, fifa # NB: FIFA (ENG); not a valid iso country n internet domain / its uk - what to use - anything better?
81
81
 
82
- ## nb: sc -> seychellen, use different two letter code st?
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?
82
+ sc, 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?
84
83
  wa, Wales, WAL, 20_779, 3_064_000, country:gb, fifa
85
84
  nd, Northern Ireland, NIR, 13_843, 1_810_900, Belfast, country:gb, fifa
86
85
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -45,7 +45,7 @@ class Loader
45
45
  end
46
46
 
47
47
  def load_fixtures_builtin( name ) # load from gem (built-in)
48
- path = "#{WorldDB.root}/db/#{name}.rb"
48
+ path = "#{WorldDB.root}/data/#{name}.rb"
49
49
 
50
50
  puts "*** loading data '#{name}' (#{path})..."
51
51
 
@@ -7,30 +7,50 @@ class City < ActiveRecord::Base
7
7
 
8
8
  belongs_to :country, :class_name => 'Country', :foreign_key => 'country_id'
9
9
  belongs_to :region, :class_name => 'Region', :foreign_key => 'region_id'
10
+
11
+ ## self referencing hierachy within cities e.g. m|metro > c|city > d|district
12
+
13
+ ## fix: use condition check for m|d|c flag?? why? why not? (NB: flags are NOT exclusive e.g. possible metro|city)
10
14
 
11
- has_many :taggings, :as => :taggable
12
- has_many :tags, :through => :taggings
15
+ ## (1) metro - level up
16
+ has_many :cities, :class_name => 'City', :foreign_key => 'city_id'
13
17
 
14
- validates :key, :format => { :with => /^[a-z]{3,}$/, :message => 'expected three or more lowercase letters a-z' }
15
- validates :code, :format => { :with => /^[A-Z_]{3}$/, :message => 'expected three uppercase letters A-Z (and _)' }, :allow_nil => true
18
+ ## (2) city
19
+ belongs_to :metro, :class_name => 'City', :foreign_key => 'city_id' ## for now alias for parent - use parent?
20
+ has_many :districts, :class_name => 'City', :foreign_key => 'city_id' ## for now alias for cities - use cities?
16
21
 
22
+ ## (3) district - level down
23
+ belongs_to :city, :class_name => 'City', :foreign_key => 'city_id' ## for now alias for parent - use parent?
17
24
 
18
- def self.by_key # order by key (a-z)
19
- self.order( 'key asc' )
20
- end
21
25
 
22
- def self.by_title # order by title (a-z)
23
- self.order( 'title asc' )
26
+ ###
27
+ # NB: use is_ for flags to avoid conflict w/ assocs (e.g. metro?, city? etc.)
28
+
29
+ def is_metro?
30
+ m? == true
24
31
  end
25
32
 
26
- def self.by_pop # order by pop(ulation)
27
- self.order( 'pop desc' )
33
+ def is_city?
34
+ c? == true
28
35
  end
29
36
 
30
- def self.by_area # order by area (in square km)
31
- self.order( 'area desc')
37
+ def is_district?
38
+ d? == true
32
39
  end
33
40
 
41
+
42
+ has_many :taggings, :as => :taggable
43
+ has_many :tags, :through => :taggings
44
+
45
+ validates :key, :format => { :with => /^[a-z]{3,}$/, :message => 'expected three or more lowercase letters a-z' }
46
+ validates :code, :format => { :with => /^[A-Z_]{3}$/, :message => 'expected three uppercase letters A-Z (and _)' }, :allow_nil => true
47
+
48
+ scope :by_key, order( 'key asc' ) # order by key (a-z)
49
+ scope :by_title, order( 'title asc' ) # order by title (a-z)
50
+ scope :by_pop, order( 'pop desc' ) # order by pop(ulation)
51
+ scope :by_popm, order( 'popm desc' ) # order by pop(ulation) metropolitan area
52
+ scope :by_area, order( 'area desc' ) # order by area (in square km)
53
+
34
54
  def title_w_synonyms
35
55
  return title if synonyms.blank?
36
56
 
@@ -18,22 +18,29 @@ class Country < ActiveRecord::Base
18
18
  validates :key, :format => { :with => /^[a-z]{2}$/, :message => 'expected two lowercase letters a-z' }
19
19
  validates :code, :format => { :with => /^[A-Z_]{3}$/, :message => 'expected three uppercase letters A-Z (and _)' }
20
20
 
21
- def self.by_key # order by key (a-z)
22
- self.order( 'key asc' )
23
- end
24
-
25
- def self.by_title # order by title (a-z)
26
- self.order( 'title asc' )
21
+ scope :by_key, order( 'key asc' ) # order by key (a-z)
22
+ scope :by_title, order( 'title asc' ) # order by title (a-z)
23
+ scope :by_code, order( 'code asc' ) # order by code (a-z)
24
+ scope :by_pop, order( 'pop desc' ) # order by pop(ulation)
25
+ scope :by_area, order( 'area desc') # order by area (in square km)
26
+
27
+ ###
28
+ # NB: use is_ for flags to avoid conflict w/ assocs
29
+
30
+ def is_supra?
31
+ s? == true
27
32
  end
28
33
 
29
- def self.by_pop # order by pop(ulation)
30
- self.order( 'pop desc' )
34
+ def is_country?
35
+ c? == true
31
36
  end
32
37
 
33
- def self.by_area # order by area (in square km)
34
- self.order( 'area desc')
38
+ def is_dependency?
39
+ d? == true
35
40
  end
36
41
 
42
+
43
+
37
44
  def title_w_synonyms
38
45
  return title if synonyms.blank?
39
46
 
@@ -13,21 +13,16 @@ module WorldDB::Models
13
13
  ## fix/todo: improve regex use [a-z][a-z0-9] | [a-z][a-z0-9_ ]+[a-z0-9] to only allow spaces and underscore inbetween; do not allow digit as first char
14
14
  validates :key, :format => { :with => /^[a-z0-9_ ]{2,}$/, :message => 'expected two or more lowercase letters a-z or 0-9 digits or space or underscore' }
15
15
 
16
+ scope :by_key, order( 'key desc' )
17
+ scope :by_title, order( 'title desc' )
18
+
16
19
  before_save :on_before_save
17
20
 
18
21
  def on_before_save
19
22
  # replace space with underscore e.g. north america becomes north_america and so on
20
23
  self.slug = key.gsub( ' ', '_' )
21
24
  end
22
-
23
- def self.by_key
24
- self.order( 'key desc' )
25
- end
26
-
27
- def self.by_title
28
- self.order( 'title desc' )
29
- end
30
-
25
+
31
26
  end # class Tag
32
27
 
33
28
  end # module WorldDB::Models
@@ -41,11 +41,14 @@ class Reader
41
41
  # load from file system
42
42
 
43
43
  def load_with_include_path( name, include_path )
44
- if name =~ /\/countries/
45
- load_countries_with_include_path( name, include_path )
44
+ if name =~ /^([a-z]{3,})\/countries/
45
+ ## auto-add continent (from folder structure) as tag
46
+ load_countries_with_include_path( name, include_path, :tags => $1 )
46
47
  elsif name =~ /\/([a-z]{2})\/cities/
48
+ ## auto-add required country code (from folder structure)
47
49
  load_cities_with_include_path( $1, name, include_path )
48
50
  elsif name =~ /\/([a-z]{2})\/regions/
51
+ ## auto-add required country code (from folder structure)
49
52
  load_regions_with_include_path( $1, name, include_path )
50
53
  else
51
54
  puts "*** error: unknown world.db fixture type >#{name}<"
@@ -53,8 +56,8 @@ class Reader
53
56
  end
54
57
  end
55
58
 
56
- def load_countries_with_include_path( name, include_path )
57
- load_fixtures_with_include_path_for( Country, name, include_path )
59
+ def load_countries_with_include_path( name, include_path, more_values={} )
60
+ load_fixtures_with_include_path_for( Country, name, include_path, more_values )
58
61
  end
59
62
 
60
63
  def load_regions_with_include_path( country_key, name, include_path )
@@ -82,8 +85,9 @@ class Reader
82
85
  load_fifa_builtin( name )
83
86
  elsif name =~ /\/iso3/
84
87
  load_iso3_builtin( name )
85
- elsif name =~ /\/countries/
86
- load_countries_builtin( name )
88
+ elsif name =~ /^([a-z]{3,})\/countries/ # e.g. africa/countries or america/countries
89
+ ## auto-add continent (from folder structure) as tag
90
+ load_countries_builtin( name, :tags => $1 )
87
91
  elsif name =~ /\/([a-z]{2})\/cities/
88
92
  load_cities_builtin( $1, name )
89
93
  elsif name =~ /\/([a-z]{2})\/regions/
@@ -94,8 +98,8 @@ class Reader
94
98
  end
95
99
  end
96
100
 
97
- def load_countries_builtin( name )
98
- load_fixtures_builtin_for( Country, name )
101
+ def load_countries_builtin( name, more_values )
102
+ load_fixtures_builtin_for( Country, name, more_values )
99
103
  end
100
104
 
101
105
  def load_regions_builtin( country_key, name )
@@ -114,7 +118,7 @@ class Reader
114
118
 
115
119
 
116
120
  def load_iso3_builtin( name )
117
- path = "#{WorldDB.root}/db/#{name}.yml"
121
+ path = "#{WorldDB.root}/data/#{name}.yml"
118
122
 
119
123
  puts "*** parsing data '#{name}' (#{path})..."
120
124
 
@@ -137,11 +141,11 @@ class Reader
137
141
 
138
142
  end
139
143
 
140
- Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
144
+ Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "world.yml.#{WorldDB::VERSION}" )
141
145
  end
142
146
 
143
147
  def load_fifa_builtin( name )
144
- path = "#{WorldDB.root}/db/#{name}.yml"
148
+ path = "#{WorldDB.root}/data/#{name}.yml"
145
149
 
146
150
  puts "*** parsing data '#{name}' (#{path})..."
147
151
 
@@ -161,11 +165,10 @@ class Reader
161
165
 
162
166
  end
163
167
 
164
- Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
168
+ Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "world.yml.#{WorldDB::VERSION}" )
165
169
  end
166
170
 
167
171
 
168
-
169
172
  private
170
173
  def load_fixtures_with_include_path_for( clazz, name, include_path, more_values={} ) # load from file system
171
174
  path = "#{include_path}/#{name}.txt"
@@ -180,7 +183,7 @@ private
180
183
  end
181
184
 
182
185
  def load_fixtures_builtin_for( clazz, name, more_values={} ) # load from gem (built-in)
183
- path = "#{WorldDB.root}/db/#{name}.txt"
186
+ path = "#{WorldDB.root}/data/#{name}.txt"
184
187
 
185
188
  puts "*** parsing data '#{name}' (#{path})..."
186
189
 
@@ -199,12 +202,25 @@ private
199
202
 
200
203
  reader.each_line do |attribs, values|
201
204
 
202
- value_numbers = []
205
+ value_numbers = []
206
+ value_tag_keys = []
203
207
 
204
- ### todo: remove attribs[:tags] from attribs? lets us pass in "default" tags - why? why not?
205
- ##
208
+ ### check for "default" tags - that is, if present attribs[:tags] remove from hash
206
209
 
207
- value_tags = []
210
+ if attribs[:tags].present?
211
+ more_tag_keys = attribs[:tags].split('|')
212
+ attribs.delete(:tags)
213
+
214
+ ## unify; replace _w/ space; remove leading n trailing whitespace
215
+ more_tag_keys = more_tag_keys.map do |key|
216
+ key = key.gsub( '_', ' ' )
217
+ key = key.strip
218
+ key
219
+ end
220
+
221
+ value_tag_keys += more_tag_keys
222
+ end
223
+
208
224
 
209
225
  if clazz == City
210
226
  attribs[ :c ] = true # assume city type by default (use metro,district to change in fixture)
@@ -256,8 +272,8 @@ private
256
272
  value_numbers << value.gsub(/[ _]/, '').to_i
257
273
  elsif (values.size==(index+1)) && value =~ /^[a-z0-9\|_ ]+$/ # tags must be last entry
258
274
 
259
- puts " processing tags: >>#{value}<<..."
260
-
275
+ puts " found tags: >>#{value}<<"
276
+
261
277
  tag_keys = value.split('|')
262
278
 
263
279
  ## unify; replace _w/ space; remove leading n trailing whitespace
@@ -267,15 +283,7 @@ private
267
283
  key
268
284
  end
269
285
 
270
- tag_keys.each do |key|
271
- tag = Tag.find_by_key( key )
272
- if tag.nil? # create tag if it doesn't exit
273
- puts " creating tag >#{key}<"
274
- tag = Tag.create!( key: key )
275
- end
276
- value_tags << tag
277
- end
278
-
286
+ value_tag_keys += tag_keys
279
287
  else
280
288
  # issue warning: unknown type for value
281
289
  puts "!!!! >>>> warning: unknown type for value >#{value}<"
@@ -313,13 +321,26 @@ private
313
321
 
314
322
  rec.update_attributes!( attribs )
315
323
 
316
- ## add tags
317
-
318
- value_tags.each do |tag|
319
- rec.tags << tag
324
+ ##################
325
+ ## add taggings
326
+
327
+ if value_tag_keys.size > 0
328
+
329
+ value_tag_keys.uniq! # remove duplicates
330
+ puts " adding #{value_tag_keys.size} taggings: >>#{value_tag_keys.join('|')}<<..."
331
+
332
+ ### fix/todo: check tag_ids and only update diff (add/remove ids)
333
+
334
+ value_tag_keys.each do |key|
335
+ tag = Tag.find_by_key( key )
336
+ if tag.nil? # create tag if it doesn't exit
337
+ puts " creating tag >#{key}<"
338
+ tag = Tag.create!( key: key )
339
+ end
340
+ rec.tags << tag
341
+ end
320
342
  end
321
-
322
- ### fix/todo: check tag_ids and only update diff (add/remove ids)
343
+
323
344
 
324
345
  end # each_line
325
346
 
@@ -18,10 +18,11 @@ create_table :countries do |t|
18
18
  t.integer :pop, :null => false # population count
19
19
  t.integer :area, :null => false # area in square km (sq. km)
20
20
  t.references :country # for supra(nationals) n depend(encies)
21
+
22
+ ## flags (use single int named flags - why? why not?
21
23
  t.boolean :s, :null => false, :default => false # supra(national) flag e.g. eu
22
24
  t.boolean :c, :null => false, :default => false # country flag (is this needed?)
23
25
  t.boolean :d, :null => false, :default => false # dependency flag
24
- t.timestamps
25
26
 
26
27
  # extras
27
28
  t.string :motor # optional auto motor (vehicle) licene plate
@@ -30,6 +31,9 @@ create_table :countries do |t|
30
31
  t.string :fifa # optional fifa country code
31
32
  t.string :net # optional internet top level domain (tld)
32
33
  t.string :wikipedia # optional wikipedia page name -- en.wikipedia.org/wiki/<name>
34
+
35
+ ## timestamp at last
36
+ t.timestamps
33
37
  end
34
38
 
35
39
 
@@ -58,18 +62,21 @@ create_table :cities do |t|
58
62
  t.string :synonyms # comma separated list of synonyms
59
63
  t.references :country, :null => false
60
64
  t.references :region # optional for now
65
+ t.references :city # optional parent (e.g. metro for city, or city for district)
61
66
  t.integer :pop # optional population count (city proper)
62
67
  t.integer :popm # optional population count (metropolitan/aglomeration)
63
68
  t.integer :area # optional area in square km (sq. km)
64
69
  t.float :lat # optional for now
65
70
  t.float :lng # optional for now
71
+
72
+ ## flags (use single int named flags - why? why not?
66
73
  t.boolean :m, :null => false, :default => false # metro flag
67
74
  t.boolean :c, :null => false, :default => false # city flag (is this needed?)
68
75
  t.boolean :d, :null => false, :default => false # district flag
69
- t.references :city # optional parent (e.g. metro for city, or city for district)
70
- t.timestamps
71
76
 
72
77
  ### t.boolean :capital, :null => false, :default => false # is national captial?
78
+
79
+ t.timestamps
73
80
  end
74
81
 
75
82
  create_table :tags do |t|
@@ -1,5 +1,5 @@
1
1
 
2
2
  module WorldDB
3
- VERSION = '0.6.6'
3
+ VERSION = '0.6.7'
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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 6
10
- version: 0.6.6
9
+ - 7
10
+ version: 0.6.7
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-30 00:00:00 Z
18
+ date: 2012-12-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -55,11 +55,11 @@ dependencies:
55
55
  requirements:
56
56
  - - ~>
57
57
  - !ruby/object:Gem::Version
58
- hash: 7
58
+ hash: 1
59
59
  segments:
60
60
  - 3
61
- - 0
62
- version: "3.0"
61
+ - 3
62
+ version: "3.3"
63
63
  type: :development
64
64
  version_requirements: *id003
65
65
  description: worlddb - world.db command line tool
@@ -70,142 +70,85 @@ extensions: []
70
70
 
71
71
  extra_rdoc_files:
72
72
  - Manifest.txt
73
- - db/africa/countries.txt
74
- - db/america/br/cities.txt
75
- - db/america/br/regions.txt
76
- - db/america/ca/cities.txt
77
- - db/america/ca/regions.txt
78
- - db/america/countries.txt
79
- - db/america/mx/cities.txt
80
- - db/america/mx/regions.txt
81
- - db/america/us/cities.txt
82
- - db/america/us/regions.txt
83
- - db/america/ve/cities.txt
84
- - db/america/ve/regions.txt
85
- - db/asia/countries.txt
86
- - db/asia/jp/cities.txt
87
- - db/europe/at/cities.txt
88
- - db/europe/at/regions.txt
89
- - db/europe/be/cities.txt
90
- - db/europe/be/regions.txt
91
- - db/europe/bg/cities.txt
92
- - db/europe/by/cities.txt
93
- - db/europe/ch/cities.txt
94
- - db/europe/countries.txt
95
- - db/europe/cy/cities.txt
96
- - db/europe/cz/cities.txt
97
- - db/europe/cz/regions.txt
98
- - db/europe/de/cities.txt
99
- - db/europe/de/regions.txt
100
- - db/europe/dk/cities.txt
101
- - db/europe/ee/cities.txt
102
- - db/europe/en/cities.txt
103
- - db/europe/en/regions.txt
104
- - db/europe/es/cities.txt
105
- - db/europe/es/regions.txt
106
- - db/europe/fi/cities.txt
107
- - db/europe/fr/cities.txt
108
- - db/europe/fr/regions.txt
109
- - db/europe/gr/cities.txt
110
- - db/europe/hr/cities.txt
111
- - db/europe/hu/cities.txt
112
- - db/europe/ie/cities.txt
113
- - db/europe/it/cities.txt
114
- - db/europe/lt/cities.txt
115
- - db/europe/lv/cities.txt
116
- - db/europe/nl/cities.txt
117
- - db/europe/no/cities.txt
118
- - db/europe/pl/cities.txt
119
- - db/europe/pt/cities.txt
120
- - db/europe/ro/cities.txt
121
- - db/europe/rs/cities.txt
122
- - db/europe/ru/cities.txt
123
- - db/europe/sc/cities.txt
124
- - db/europe/se/cities.txt
125
- - db/europe/tr/cities.txt
126
- - db/europe/ua/cities.txt
127
- - db/europe/wa/cities.txt
128
- - db/oceania/au/cities.txt
129
- - db/oceania/countries.txt
130
73
  files:
131
74
  - History.markdown
132
75
  - Manifest.txt
133
76
  - README.markdown
134
77
  - Rakefile
135
78
  - bin/worlddb
136
- - db/africa/countries.txt
137
- - db/africa/de.countries.yml
138
- - db/africa/en.wikipedia.yml
139
- - db/africa/fifa.yml
140
- - db/africa/iso3.yml
141
- - db/america/br/cities.txt
142
- - db/america/br/regions.txt
143
- - db/america/ca/cities.txt
144
- - db/america/ca/regions.txt
145
- - db/america/countries.motor.yml
146
- - db/america/countries.txt
147
- - db/america/de.countries.yml
148
- - db/america/en.wikipedia.yml
149
- - db/america/es.countries.yml
150
- - db/america/mx/cities.txt
151
- - db/america/mx/regions.txt
152
- - db/america/us/cities.txt
153
- - db/america/us/regions.txt
154
- - db/america/ve/cities.txt
155
- - db/america/ve/regions.txt
156
- - db/asia/countries.txt
157
- - db/asia/de.countries.yml
158
- - db/asia/en.wikipedia.yml
159
- - db/asia/jp/cities.txt
160
- - db/europe/at/cities.txt
161
- - db/europe/at/regions.txt
162
- - db/europe/be/cities.txt
163
- - db/europe/be/regions.txt
164
- - db/europe/bg/cities.txt
165
- - db/europe/by/cities.txt
166
- - db/europe/ch/cities.txt
167
- - db/europe/countries.txt
168
- - db/europe/cy/cities.txt
169
- - db/europe/cz/cities.txt
170
- - db/europe/cz/regions.txt
171
- - db/europe/de.countries.yml
172
- - db/europe/de/cities.txt
173
- - db/europe/de/regions.txt
174
- - db/europe/dk/cities.txt
175
- - db/europe/ee/cities.txt
176
- - db/europe/en.wikipedia.yml
177
- - db/europe/en/cities.txt
178
- - db/europe/en/regions.txt
179
- - db/europe/es.countries.yml
180
- - db/europe/es/cities.txt
181
- - db/europe/es/regions.txt
182
- - db/europe/fi/cities.txt
183
- - db/europe/fr/cities.txt
184
- - db/europe/fr/regions.txt
185
- - db/europe/gr/cities.txt
186
- - db/europe/hr/cities.txt
187
- - db/europe/hu/cities.txt
188
- - db/europe/ie/cities.txt
189
- - db/europe/it/cities.txt
190
- - db/europe/lt/cities.txt
191
- - db/europe/lv/cities.txt
192
- - db/europe/nl/cities.txt
193
- - db/europe/no/cities.txt
194
- - db/europe/pl/cities.txt
195
- - db/europe/pt/cities.txt
196
- - db/europe/ro/cities.txt
197
- - db/europe/rs/cities.txt
198
- - db/europe/ru/cities.txt
199
- - db/europe/sc/cities.txt
200
- - db/europe/se/cities.txt
201
- - db/europe/tr/cities.txt
202
- - db/europe/ua/cities.txt
203
- - db/europe/wa/cities.txt
204
- - db/oceania/au/cities.txt
205
- - db/oceania/countries.txt
206
- - db/oceania/de.countries.yml
207
- - db/oceania/en.wikipedia.yml
208
- - db/tags.yml
79
+ - data/africa/countries.txt
80
+ - data/africa/de.countries.yml
81
+ - data/africa/en.wikipedia.yml
82
+ - data/africa/fifa.yml
83
+ - data/africa/iso3.yml
84
+ - data/america/br/cities.txt
85
+ - data/america/br/regions.txt
86
+ - data/america/ca/cities.txt
87
+ - data/america/ca/regions.txt
88
+ - data/america/countries.motor.yml
89
+ - data/america/countries.txt
90
+ - data/america/de.countries.yml
91
+ - data/america/en.wikipedia.yml
92
+ - data/america/es.countries.yml
93
+ - data/america/mx/cities.txt
94
+ - data/america/mx/regions.txt
95
+ - data/america/us/cities.txt
96
+ - data/america/us/regions.txt
97
+ - data/america/ve/cities.txt
98
+ - data/america/ve/regions.txt
99
+ - data/asia/countries.txt
100
+ - data/asia/de.countries.yml
101
+ - data/asia/en.wikipedia.yml
102
+ - data/asia/jp/cities.txt
103
+ - data/europe/at/cities.txt
104
+ - data/europe/at/regions.txt
105
+ - data/europe/be/cities.txt
106
+ - data/europe/be/regions.txt
107
+ - data/europe/bg/cities.txt
108
+ - data/europe/by/cities.txt
109
+ - data/europe/ch/cities.txt
110
+ - data/europe/countries.txt
111
+ - data/europe/cy/cities.txt
112
+ - data/europe/cz/cities.txt
113
+ - data/europe/cz/regions.txt
114
+ - data/europe/de.countries.yml
115
+ - data/europe/de/cities.txt
116
+ - data/europe/de/regions.txt
117
+ - data/europe/dk/cities.txt
118
+ - data/europe/ee/cities.txt
119
+ - data/europe/en.wikipedia.yml
120
+ - data/europe/en/cities.txt
121
+ - data/europe/en/regions.txt
122
+ - data/europe/es.countries.yml
123
+ - data/europe/es/cities.txt
124
+ - data/europe/es/regions.txt
125
+ - data/europe/fi/cities.txt
126
+ - data/europe/fr/cities.txt
127
+ - data/europe/fr/regions.txt
128
+ - data/europe/gr/cities.txt
129
+ - data/europe/hr/cities.txt
130
+ - data/europe/hu/cities.txt
131
+ - data/europe/ie/cities.txt
132
+ - data/europe/it/cities.txt
133
+ - data/europe/lt/cities.txt
134
+ - data/europe/lv/cities.txt
135
+ - data/europe/nl/cities.txt
136
+ - data/europe/no/cities.txt
137
+ - data/europe/pl/cities.txt
138
+ - data/europe/pt/cities.txt
139
+ - data/europe/ro/cities.txt
140
+ - data/europe/rs/cities.txt
141
+ - data/europe/ru/cities.txt
142
+ - data/europe/sc/cities.txt
143
+ - data/europe/se/cities.txt
144
+ - data/europe/tr/cities.txt
145
+ - data/europe/ua/cities.txt
146
+ - data/europe/wa/cities.txt
147
+ - data/oceania/au/cities.txt
148
+ - data/oceania/countries.txt
149
+ - data/oceania/de.countries.yml
150
+ - data/oceania/en.wikipedia.yml
151
+ - data/tags.yml
209
152
  - lib/worlddb.rb
210
153
  - lib/worlddb/cli/opts.rb
211
154
  - lib/worlddb/cli/runner.rb
@@ -225,8 +168,8 @@ files:
225
168
  - lib/worlddb/utils.rb
226
169
  - lib/worlddb/version.rb
227
170
  homepage: http://geraldb.github.com/world.db
228
- licenses: []
229
-
171
+ licenses:
172
+ - Public Domain
230
173
  post_install_message:
231
174
  rdoc_options:
232
175
  - --main