worlddb 0.1.0 → 0.2.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.
@@ -1,5 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
+
4
+ #########
5
+ # sources:
6
+ # http://en.wikipedia.org/wiki/List_of_cities_and_towns_in_Austria
7
+ # http://en.wikipedia.org/wiki/List_of_cities_in_Austria_over_5,000_population_(2001_census)
8
+
9
+
10
+
11
+
3
12
  at = Country.find_by_key!( 'at' )
4
13
 
5
14
 
@@ -20,31 +29,39 @@ regions_at = [
20
29
  Region.create_from_ary!( regions_at, country: at )
21
30
 
22
31
  cities_at = [
23
- ['wien', 'Wien|Vienna', 'region:wien'],
32
+ ['wien', 'Wien|Vienna', 'region:wien', 1664146],
24
33
 
25
- ['stpoelten', 'St. Pölten', 'region:noe'],
26
- ['moedling', 'Mödling|Moedling', 'region:noe'],
27
- ['wrneustadt', 'Wiener Neustadt|Wr. Neustadt', 'region:noe'],
28
- ['horn', 'Horn', 'region:noe'],
34
+ ['stpoelten', 'St. Pölten', 'region:noe', 51360],
35
+ ['wrneustadt', 'Wiener Neustadt|Wr. Neustadt', 'region:noe', 39940],
36
+ ['moedling', 'Mödling|Moedling', 'region:noe', 20649],
37
+ ['horn', 'Horn', 'region:noe', 6411], # < 10000 pop
29
38
 
30
- ['linz', 'Linz', 'region:ooe'],
31
- ['ried', 'Ried', 'region:ooe'],
39
+ ['linz', 'Linz', 'region:ooe', 188894],
40
+ ['wels', 'Wels', 'region:ooe', 58623],
41
+ ['steyr', 'Steyr', 'region:ooe', 38979],
42
+ ['ried', 'Ried im Innkreis', 'region:ooe', 11585],
32
43
 
33
- ['mattersburg', 'Mattersburg', 'region:bgld'],
44
+ ['eisenstadt', 'Eisenstadt', 'region:bgld', 12367],
45
+ ['mattersburg', 'Mattersburg', 'region:bgld', 6256], # < 10000 pop
34
46
 
35
- ['graz', 'Graz', 'region:stmk'],
36
- ['hartberg', 'Hartberg', 'region:stmk'],
37
- ['kapfenberg', 'Kapfenberg', 'region:stmk'],
47
+ ['graz', 'Graz', 'region:stmk', 247698],
48
+ ['kapfenberg', 'Kapfenberg', 'region:stmk', 21928],
49
+ ['hartberg', 'Hartberg', 'region:stmk', 6547], # < 10000 pop
38
50
 
39
- ['salzburg', 'Salzburg', 'region:sbg'],
40
- ['groedig', 'Grödig', 'region:sbg'],
51
+ ['salzburg', 'Salzburg', 'region:sbg', 149018],
52
+ ['groedig', 'Grödig', 'region:sbg', 6638], # < 10000 pop
41
53
 
42
- ['wolfsberg', 'Wolfsberg', 'region:ktn'],
54
+ ['klagenfurt', 'Klagenfurt', 'region:ktn', 92397],
55
+ ['villach', 'Villach', 'region:ktn', 58480],
56
+ ['wolfsberg', 'Wolfsberg', 'region:ktn', 25361],
43
57
 
44
- ['innsbruck', 'Innsbruck', 'region:tirol'],
58
+ ['innsbruck', 'Innsbruck', 'region:tirol', 117693],
45
59
 
46
- ['altach', 'Altach', 'region:vbg'],
47
- ['lustenau', 'Lustenau', 'region:vbg']
60
+ ['dornbirn', 'Dornbirn', 'region:vbg', 44243],
61
+ ['feldkirch', 'Feldkirch', 'region:vbg', 30093],
62
+ ['bregenz', 'Bregenz', 'region:vbg', 27148],
63
+ ['lustenau', 'Lustenau', 'region:vbg', 20606],
64
+ ['altach', 'Altach', 'region:vbg', 5704], # < 10000 pop
48
65
  ]
49
66
 
50
67
  City.create_from_ary!( cities_at, country: at )
@@ -46,6 +46,42 @@ module WorldDB
46
46
  Runner.new.run(ARGV)
47
47
  end
48
48
 
49
+
50
+ # load built-in (that is, bundled within the gem) named seeds
51
+ # - pass in an array of seed names e.g. [ 'countries', 'at/cities', 'de/cities' ] etc.
52
+
53
+ def self.load( ary )
54
+ loader = Loader.new
55
+ ary.each do |name|
56
+ loader.load_fixtures_builtin( name )
57
+ end
58
+ end
59
+
60
+
61
+ class Deleter
62
+ ## todo: move into its own file???
63
+
64
+ ## make models available in worlddb module by default with namespace
65
+ # e.g. lets you use City instead of Models::City
66
+ include WorldDB::Models
67
+
68
+ def run( args=[] )
69
+ # for now delete all tables
70
+
71
+ Country.delete_all
72
+ City.delete_all
73
+ Region.delete_all
74
+ Prop.delete_all
75
+ end
76
+
77
+ end
78
+
79
+ # delete ALL records (use with care!)
80
+ def self.delete!
81
+ Deleter.new.run
82
+ end # method delete!
83
+
84
+
49
85
  end # module WorldDB
50
86
 
51
87
 
@@ -85,7 +85,7 @@ EOS
85
85
  end
86
86
 
87
87
  if opts.delete?
88
- # tbd
88
+ WorldDB.delete!
89
89
  end
90
90
 
91
91
  Loader.new( logger ).run( opts, args ) # load ruby fixtures
@@ -26,10 +26,14 @@ class City < ActiveRecord::Base
26
26
 
27
27
  attr = attr.merge( more_values )
28
28
 
29
+ value_numbers = []
30
+
29
31
  ## check for optional values
30
32
  values[2..-1].each do |value|
31
33
  if value.is_a? Country
32
34
  attr[ :country_id ] = value.id
35
+ elsif value.is_a? Numeric
36
+ value_numbers << value
33
37
  elsif value =~ /^region:/ ## region:
34
38
  value_region_key = value[7..-1] ## cut off region: prefix
35
39
  value_region = Region.find_by_key!( value_region_key )
@@ -39,6 +43,12 @@ class City < ActiveRecord::Base
39
43
  end
40
44
  end
41
45
 
46
+ if value_numbers.size > 0
47
+ attr[ :pop ] = value_numbers[0]
48
+ attr[ :area ] = value_numbers[1]
49
+ end
50
+
51
+
42
52
  City.create!( attr )
43
53
  end # each city
44
54
  end
@@ -11,10 +11,12 @@ def self.up
11
11
  ActiveRecord::Schema.define do
12
12
 
13
13
  create_table :countries do |t|
14
- t.string :title, :null => false
15
- t.string :key, :null => false
16
- t.string :tag, :null => false # short three letter tag (FIFA country code)
17
- t.string :synonyms # comma separated list of synonyms
14
+ t.string :title, :null => false
15
+ t.string :key, :null => false
16
+ t.string :tag, :null => false # short three letter tag (FIFA country code)
17
+ t.string :synonyms # comma separated list of synonyms
18
+ t.integer :pop # optional population count
19
+ t.integer :area # optional area in square km (sq. km)
18
20
  t.timestamps
19
21
  end
20
22
 
@@ -23,6 +25,8 @@ create_table :regions do |t|
23
25
  t.string :key, :null => false
24
26
  t.string :synonyms # comma separated list of synonyms
25
27
  t.references :country, :null => false
28
+ t.integer :pop # optional population count
29
+ t.integer :area # optional area in square km (sq. km)
26
30
  t.timestamps
27
31
  end
28
32
 
@@ -32,6 +36,9 @@ create_table :cities do |t|
32
36
  t.string :synonyms # comma separated list of synonyms
33
37
  t.references :country, :null => false
34
38
  t.references :region # optional for now
39
+ t.integer :pop # optional population count
40
+ t.integer :area # optional area in square km (sq. km)
41
+ t.boolean :capital, :null => false, :default => false # is national captial?
35
42
  t.timestamps
36
43
  end
37
44
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module WorldDB
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
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: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
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-05 00:00:00 Z
18
+ date: 2012-11-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord