worlddb 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,47 +110,38 @@ class City < ActiveRecord::Base
110
110
  new_attributes[ :c ] = true # assume city type by default (use metro,district to change in fixture)
111
111
 
112
112
  ## check for optional values
113
-
114
- ### fix: todo: use matcher from ValueHelper !!!!!
115
113
 
116
114
  values.each_with_index do |value,index|
117
- if value =~ /^region:/ ## region:
118
- value_region_key = value[7..-1] ## cut off region: prefix
119
- ## NB: requires country_id to make unique!
120
- value_region = Region.find_by_key_and_country_id!( value_region_key, new_attributes[:country_id] )
121
- new_attributes[ :region_id ] = value_region.id
122
- elsif value =~ /^metro$/ ## metro(politan area)
123
- new_attributes[ :c ] = false # turn off default c|city flag; make it m|metro only
124
- new_attributes[ :m ] = true
125
- elsif value =~ /^country:/ ## country:
126
- value_country_key = value[8..-1] ## cut off country: prefix
127
- value_country = Country.find_by_key!( value_country_key )
128
- new_attributes[ :country_id ] = value_country.id
129
- elsif value =~ /^metro:/ ## metro:
130
- value_city_key = value[6..-1] ## cut off metro: prefix
131
- value_city = City.find_by_key!( value_city_key )
132
- new_attributes[ :city_id ] = value_city.id
133
- elsif value =~ /^city:/ ## city:
134
- value_city_key = value[5..-1] ## cut off city: prefix
135
- value_city = City.find_by_key!( value_city_key )
136
- new_attributes[ :city_id ] = value_city.id
137
- new_attributes[ :c ] = false # turn off default c|city flag; make it d|district only
138
- new_attributes[ :d ] = true
139
- elsif value =~ /^m:/ ## m:
140
- value_popm_str = value[2..-1] ## cut off m: prefix
141
- value_popm = value_popm_str.gsub(/[ _]/, '').to_i
142
- new_attributes[ :popm ] = value_popm
143
- new_attributes[ :m ] = true # auto-mark city as m|metro too
144
- elsif is_region?( value ) ## assume region code e.g. TX for city
145
- value_region = Region.find_by_key_and_country_id!( value.downcase, new_attributes[:country_id] )
146
- new_attributes[ :region_id ] = value_region.id
147
- elsif value =~ /^[A-Z]{2,3}$/ ## assume two or three-letter code
115
+ if match_region_for_country( value, new_attributes[:country_id] ) do |region|
116
+ new_attributes[ :region_id ] = region.id
117
+ end
118
+ elsif match_country( value ) do |country|
119
+ new_attributes[ :country_id ] = country.id
120
+ end
121
+ elsif match_metro( value ) do |city|
122
+ new_attributes[ :city_id ] = city.id
123
+ end
124
+ elsif match_metro_pop( value ) do |num| # m:
125
+ new_attributes[ :popm ] = num
126
+ new_attributes[ :m ] = true # auto-mark city as m|metro too
127
+ end
128
+ elsif match_metro_flag( value ) do |_| # metro(politan area)
129
+ new_attributes[ :c ] = false # turn off default c|city flag; make it m|metro only
130
+ new_attributes[ :m ] = true
131
+ end
132
+ elsif match_city( value ) do |city| # parent city for district
133
+ new_attributes[ :city_id ] = city.id
134
+ new_attributes[ :c ] = false # turn off default c|city flag; make it d|district only
135
+ new_attributes[ :d ] = true
136
+ end
137
+ elsif match_km_squared( value ) do |num| # allow numbers like 453 km²
138
+ value_numbers << num
139
+ end
140
+ elsif match_number( value ) do |num| # numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
141
+ value_numbers << num
142
+ end
143
+ elsif value =~ /^[A-Z]{3}$/ ## assume three-letter code
148
144
  new_attributes[ :code ] = value
149
- elsif value =~ /^([0-9][0-9 _]+[0-9]|[0-9]{1,2})(?:\s*(?:km2|km²)\s*)$/
150
- ## allow numbers like 453 km²
151
- value_numbers << value.gsub( 'km2', '').gsub( 'km²', '' ).gsub(/[ _]/, '').to_i
152
- elsif value =~ /^([0-9][0-9 _]+[0-9])|([0-9]{1,2})$/ ## numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
153
- value_numbers << value.gsub(/[ _]/, '').to_i
154
145
  elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
155
146
  logger.debug " found tags: >>#{value}<<"
156
147
  value_tag_keys += find_tags( value )
@@ -163,7 +154,7 @@ class City < ActiveRecord::Base
163
154
  if value_numbers.size > 0
164
155
  new_attributes[ :pop ] = value_numbers[0] # assume first number is pop for cities
165
156
  new_attributes[ :area ] = value_numbers[1]
166
- end # if value_numbers.size > 0
157
+ end
167
158
 
168
159
  rec = City.find_by_key( new_attributes[ :key ] )
169
160
 
@@ -92,33 +92,33 @@ class Country < ActiveRecord::Base
92
92
 
93
93
 
94
94
  new_attributes[ :c ] = true # assume country type by default (use supra,depend to change)
95
-
95
+
96
96
  ## check for optional values
97
97
  values.each_with_index do |value,index|
98
- if value =~ /^supra$/ ## supra(national)
99
- new_attributes[ :c ] = false # turn off default c|country flag; make it s|supra only
100
- new_attributes[ :s ] = true
101
- ## auto-add tag supra
102
- value_tag_keys << 'supra'
103
- elsif value =~ /^supra:/ ## supra:
104
- value_country_key = value[6..-1] ## cut off supra: prefix
105
- value_country = Country.find_by_key!( value_country_key )
106
- new_attributes[ :country_id ] = value_country.id
107
- elsif value =~ /^country:/ ## country:
108
- value_country_key = value[8..-1] ## cut off country: prefix
109
- value_country = Country.find_by_key!( value_country_key )
110
- new_attributes[ :country_id ] = value_country.id
111
- new_attributes[ :c ] = false # turn off default c|country flag; make it d|depend only
112
- new_attributes[ :d ] = true
113
- ## auto-add tag supra
114
- value_tag_keys << 'territory' # rename tag to dependency? why? why not?
98
+ if match_supra_flag( value ) do |_| # supra(national)
99
+ new_attributes[ :c ] = false # turn off default c|country flag; make it s|supra only
100
+ new_attributes[ :s ] = true
101
+ ## auto-add tag supra
102
+ value_tag_keys << 'supra'
103
+ end
104
+ elsif match_supra( value ) do |country| # supra:
105
+ new_attributes[ :country_id ] = country.id
106
+ end
107
+ elsif match_country( value ) do |country| # country:
108
+ new_attributes[ :country_id ] = country.id
109
+ new_attributes[ :c ] = false # turn off default c|country flag; make it d|depend only
110
+ new_attributes[ :d ] = true
111
+ ## auto-add tag supra
112
+ value_tag_keys << 'territory' # rename tag to dependency? why? why not?
113
+ end
114
+ elsif match_km_squared( value ) do |num| # allow numbers like 453 km²
115
+ value_numbers << num
116
+ end
117
+ elsif match_number( value ) do |num| # numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
118
+ value_numbers << num
119
+ end
115
120
  elsif value =~ /^[A-Z]{2,3}$/ ## assume two or three-letter code
116
121
  new_attributes[ :code ] = value
117
- elsif value =~ /^([0-9][0-9 _]+[0-9]|[0-9]{1,2})(?:\s*(?:km2|km²)\s*)$/
118
- ## allow numbers like 453 km²
119
- value_numbers << value.gsub( 'km2', '').gsub( 'km²', '' ).gsub(/[ _]/, '').to_i
120
- elsif value =~ /^([0-9][0-9 _]+[0-9])|([0-9]{1,2})$/ ## numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
121
- value_numbers << value.gsub(/[ _]/, '').to_i
122
122
  elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
123
123
  logger.debug " found tags: >>#{value}<<"
124
124
  value_tag_keys += find_tags( value )
@@ -61,17 +61,17 @@ class Region < ActiveRecord::Base
61
61
 
62
62
  ## check for optional values
63
63
  values.each_with_index do |value,index|
64
- if value =~ /^country:/ ## country:
65
- value_country_key = value[8..-1] ## cut off country: prefix
66
- value_country = Country.find_by_key!( value_country_key )
67
- new_attributes[ :country_id ] = value_country.id
64
+ if match_country( value ) do |country| # country:
65
+ new_attributes[ :country_id ] = country.id
66
+ end
67
+ elsif match_km_squared( value ) do |num| # allow numbers like 453 km²
68
+ value_numbers << num
69
+ end
70
+ elsif match_number( value ) do |num| # numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
71
+ value_numbers << num
72
+ end
68
73
  elsif value =~ /^[A-Z]{2,3}$/ ## assume two or three-letter code
69
74
  new_attributes[ :code ] = value
70
- elsif value =~ /^([0-9][0-9 _]+[0-9]|[0-9]{1,2})(?:\s*(?:km2|km²)\s*)$/
71
- ## allow numbers like 453 km²
72
- value_numbers << value.gsub( 'km2', '').gsub( 'km²', '' ).gsub(/[ _]/, '').to_i
73
- elsif value =~ /^([0-9][0-9 _]+[0-9])|([0-9]{1,2})$/ ## numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
74
- value_numbers << value.gsub(/[ _]/, '').to_i
75
75
  elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
76
76
  logger.debug " found tags: >>#{value}<<"
77
77
  value_tag_keys += find_tags( value )
@@ -113,6 +113,7 @@ class Region < ActiveRecord::Base
113
113
  country_id: rec.country_id )
114
114
 
115
115
  ### todo/fix: add captial ref to country/region
116
+ ## todo/fix: use update_from_title and only allow one capital city
116
117
 
117
118
 
118
119
  ##################
@@ -1,6 +1,6 @@
1
1
 
2
2
  module WorldDb
3
- VERSION = '1.7.0' # sync version w/ sport.db - why? why not?
3
+ VERSION = '1.7.1' # sync version w/ sport.db - why? why not?
4
4
  end
5
5
 
6
6
  ###########################################
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: textutils
16
- requirement: &81436760 !ruby/object:Gem::Requirement
16
+ requirement: &78717170 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81436760
24
+ version_requirements: *78717170
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commander
27
- requirement: &81436540 !ruby/object:Gem::Requirement
27
+ requirement: &78716950 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 4.1.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *81436540
35
+ version_requirements: *78716950
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activerecord
38
- requirement: &81436330 !ruby/object:Gem::Requirement
38
+ requirement: &78716740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.2'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *81436330
46
+ version_requirements: *78716740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &81436110 !ruby/object:Gem::Requirement
49
+ requirement: &78716520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.10'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *81436110
57
+ version_requirements: *78716520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &81435890 !ruby/object:Gem::Requirement
60
+ requirement: &78716300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *81435890
68
+ version_requirements: *78716300
69
69
  description: worlddb - world.db command line tool
70
70
  email: opensport@googlegroups.com
71
71
  executables: