worlddb 0.6.3 → 0.6.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.
- data/db/europe/countries.txt +1 -1
- data/db/europe/cz/cities.txt +4 -4
- data/lib/worlddb/models/city.rb +16 -0
- data/lib/worlddb/models/country.rb +5 -2
- data/lib/worlddb/models/tag.rb +18 -0
- data/lib/worlddb/reader.rb +2 -2
- data/lib/worlddb/schema.rb +1 -0
- data/lib/worlddb/version.rb +1 -1
- metadata +3 -3
data/db/europe/countries.txt
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
|
28
28
|
## eu 27 (+ euro 17)
|
29
29
|
|
30
|
-
eu, European Union, EUR, 4_324_782, 503_492_041, supra # NB: no FIFA code exists; use EUR
|
30
|
+
eu, European Union, EUR, 4_324_782, 503_492_041, supra, g20 # NB: no FIFA code exists; use EUR
|
31
31
|
|
32
32
|
## todo: auto-add tag eu?? for supra:eu?
|
33
33
|
|
data/db/europe/cz/cities.txt
CHANGED
@@ -19,8 +19,8 @@ pardubice, Pardubice, region:pa, 91_073
|
|
19
19
|
karlovyvary, Karlovy Vary [Carlsbad], region:ka, 53_737
|
20
20
|
kutnahora, Kutná Hora, region:st, 20_839
|
21
21
|
|
22
|
-
tabor, Tábor,
|
23
|
-
krumlov, Český Krumlov region:jc, 13_752
|
24
|
-
trebon, Třeboň,
|
22
|
+
tabor, Tábor, region:jc, 35_769
|
23
|
+
krumlov, Český Krumlov, region:jc, 13_752
|
24
|
+
trebon, Třeboň, region:jc, 8_840
|
25
25
|
|
26
|
-
mikulov, Mikulov,
|
26
|
+
mikulov, Mikulov, region:jm, 7_624
|
data/lib/worlddb/models/city.rb
CHANGED
@@ -15,6 +15,22 @@ class City < ActiveRecord::Base
|
|
15
15
|
validates :code, :format => { :with => /^[A-Z_]{3}$/, :message => 'expected three uppercase letters A-Z (and _)' }, :allow_nil => true
|
16
16
|
|
17
17
|
|
18
|
+
def self.by_key # order by key (a-z)
|
19
|
+
self.order( 'key asc' )
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.by_title # order by title (a-z)
|
23
|
+
self.order( 'title asc' )
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.by_pop # order by pop(ulation)
|
27
|
+
self.order( 'pop desc' )
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.by_area # order by area (in square km)
|
31
|
+
self.order( 'area desc')
|
32
|
+
end
|
33
|
+
|
18
34
|
def title_w_synonyms
|
19
35
|
return title if synonyms.blank?
|
20
36
|
|
@@ -18,17 +18,20 @@ 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
|
21
24
|
|
22
25
|
def self.by_title # order by title (a-z)
|
23
26
|
self.order( 'title asc' )
|
24
27
|
end
|
25
28
|
|
26
29
|
def self.by_pop # order by pop(ulation)
|
27
|
-
self.order( 'pop
|
30
|
+
self.order( 'pop desc' )
|
28
31
|
end
|
29
32
|
|
30
33
|
def self.by_area # order by area (in square km)
|
31
|
-
self.order( 'area
|
34
|
+
self.order( 'area desc')
|
32
35
|
end
|
33
36
|
|
34
37
|
def title_w_synonyms
|
data/lib/worlddb/models/tag.rb
CHANGED
@@ -9,6 +9,24 @@ module WorldDB::Models
|
|
9
9
|
has_many :cities, :through => :taggings, :source => :taggable, :source_type => 'WorldDB::Models::City', :class_name => 'City'
|
10
10
|
has_many :countries, :through => :taggings, :source => :taggable, :source_type => 'WorldDB::Models::Country', :class_name => 'Country'
|
11
11
|
has_many :regions, :through => :taggings, :source => :taggable, :source_type => 'WorldDB::Models::Region', :class_name => 'Region'
|
12
|
+
|
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
|
+
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
|
+
|
16
|
+
before_save :on_before_save
|
17
|
+
|
18
|
+
def on_before_save
|
19
|
+
# replace space with underscore e.g. north america becomes north_america and so on
|
20
|
+
self.slug = key.gsub( ' ', '_' )
|
21
|
+
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
|
12
30
|
|
13
31
|
end # class Tag
|
14
32
|
|
data/lib/worlddb/reader.rb
CHANGED
@@ -227,8 +227,8 @@ private
|
|
227
227
|
attribs[ :pop ] = value_numbers[0] # assume first number is pop for cities
|
228
228
|
attribs[ :area ] = value_numbers[1]
|
229
229
|
else # countries,regions
|
230
|
-
attribs[ :area ] = value_numbers[
|
231
|
-
attribs[ :pop ] = value_numbers[
|
230
|
+
attribs[ :area ] = value_numbers[0]
|
231
|
+
attribs[ :pop ] = value_numbers[1]
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
data/lib/worlddb/schema.rb
CHANGED
data/lib/worlddb/version.rb
CHANGED
metadata
CHANGED