beerdb 0.6.10 → 0.6.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/beerdb/models/brewery.rb +76 -0
- data/lib/beerdb/version.rb +1 -1
- metadata +12 -12
@@ -40,6 +40,27 @@ class Brewery < ActiveRecord::Base
|
|
40
40
|
end
|
41
41
|
|
42
42
|
|
43
|
+
|
44
|
+
## todo/fix:
|
45
|
+
# move to textutils - use AddressHelper ??
|
46
|
+
# todo: add _in_adr or _in_addr to name
|
47
|
+
|
48
|
+
def self.find_city_for_country( country_key, address )
|
49
|
+
|
50
|
+
lines = address.split( '//' )
|
51
|
+
|
52
|
+
if country_key == 'at' || country_key == 'de'
|
53
|
+
# first line strip numbers (assuming zip code) and whitespace
|
54
|
+
line1 = lines[0]
|
55
|
+
line1 = line1.gsub( /\b[0-9]+\b/, '' ) # use word boundries (why? why not?)
|
56
|
+
line1 = line1.strip
|
57
|
+
line1 # assume its the city
|
58
|
+
else
|
59
|
+
nil # unsupported country/address schema for now
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
43
64
|
def self.create_or_update_from_values( new_attributes, values )
|
44
65
|
|
45
66
|
## fix: add/configure logger for ActiveRecord!!!
|
@@ -141,6 +162,61 @@ class Brewery < ActiveRecord::Base
|
|
141
162
|
|
142
163
|
rec.update_attributes!( new_attributes )
|
143
164
|
|
165
|
+
|
166
|
+
##############################
|
167
|
+
# auto-add city if not present and country n region present
|
168
|
+
|
169
|
+
if new_attributes[:city_id].blank? &&
|
170
|
+
new_attributes[:country_id].present? &&
|
171
|
+
new_attributes[:region_id].present?
|
172
|
+
|
173
|
+
country_key = rec.country.key
|
174
|
+
|
175
|
+
if county_key == 'at' || country_key == 'de'
|
176
|
+
|
177
|
+
## todo: use find_city_in_adr_for_country ?? too long ?? use adr or addr
|
178
|
+
city_title = find_city_for_country( country_key, new_attributes[:address] )
|
179
|
+
|
180
|
+
if city_title.present?
|
181
|
+
|
182
|
+
# remove optional english translation in square brackets ([]) e.g. Wien [Vienna]
|
183
|
+
city_title = TextUtils.strip_translations( city_title )
|
184
|
+
# remove optional longer title part in {} e.g. Ottakringer {Bio} or {Alkoholfrei}
|
185
|
+
city_title = TextUtils.strip_tags( city_title )
|
186
|
+
|
187
|
+
city_key = TextUtils.title_to_key( city_title )
|
188
|
+
|
189
|
+
city = City.find_by_key( city_key )
|
190
|
+
|
191
|
+
city_attributes = {
|
192
|
+
title: city_title,
|
193
|
+
country_id: rec.country_id,
|
194
|
+
region_id: rec.region_id
|
195
|
+
### fix/todo: add new autoadd flag too?
|
196
|
+
}
|
197
|
+
|
198
|
+
if city.present?
|
199
|
+
logger.info "update City #{city.id}-#{city.key}:"
|
200
|
+
else
|
201
|
+
logger.info "create City:"
|
202
|
+
city = City.new
|
203
|
+
city_attributes[ :key ] = city_key # NB: new record; include/update key
|
204
|
+
end
|
205
|
+
|
206
|
+
logger.info city_attributes.to_json
|
207
|
+
|
208
|
+
city.update_attributes!( city_attributes )
|
209
|
+
|
210
|
+
## now at last add city_id to brewery!
|
211
|
+
rec.city_id = city.id
|
212
|
+
rec.save!
|
213
|
+
else
|
214
|
+
logger.warn "auto-add city (#{country_key}) >>#{new_attributes[:address]}<< failed; no city title found"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
|
144
220
|
###################
|
145
221
|
# auto-add brands if presents
|
146
222
|
|
data/lib/beerdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beerdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &76843520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *76843520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: worlddb
|
27
|
-
requirement: &
|
27
|
+
requirement: &76843280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.6'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *76843280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: commander
|
38
|
-
requirement: &
|
38
|
+
requirement: &76843050 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 4.1.3
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *76843050
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &76842820 !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: *
|
57
|
+
version_requirements: *76842820
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: hoe
|
60
|
-
requirement: &
|
60
|
+
requirement: &76842600 !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: *
|
68
|
+
version_requirements: *76842600
|
69
69
|
description: beerdb - beer.db command line tool
|
70
70
|
email: beerdb@googlegroups.com
|
71
71
|
executables:
|