worlddb 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
@@ -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, region:jc, 35_769
23
- krumlov, Český Krumlov region:jc, 13_752
24
- trebon, Třeboň, region:jc, 8_840
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, region:jm, 7_624
26
+ mikulov, Mikulov, region:jm, 7_624
@@ -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 asc' )
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 asc')
34
+ self.order( 'area desc')
32
35
  end
33
36
 
34
37
  def title_w_synonyms
@@ -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
 
@@ -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[1]
231
- attribs[ :pop ] = value_numbers[0]
230
+ attribs[ :area ] = value_numbers[0]
231
+ attribs[ :pop ] = value_numbers[1]
232
232
  end
233
233
  end
234
234
 
@@ -68,6 +68,7 @@ end
68
68
 
69
69
  create_table :tags do |t|
70
70
  t.string :key, :null => false
71
+ t.string :slug, :null => false
71
72
  t.string :title # todo: make required?
72
73
  ## todo: add parent or similar for hierachy (for tag stacks/packs)
73
74
  t.timestamps
@@ -1,5 +1,5 @@
1
1
 
2
2
  module WorldDB
3
- VERSION = '0.6.3'
3
+ VERSION = '0.6.4'
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: 1
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer