beerdb-models 1.0.1 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 333f48b7fbc66cb2fa3d9ef78a9815496c093fc7
4
- data.tar.gz: 283dc0368e9bdf46e69f8a774ed6a6daca3efbac
3
+ metadata.gz: 4e0814546ffaf1bdce1f0a10a33183cb5d3642c4
4
+ data.tar.gz: 95860781d2554c27001e6db34eb1b926bba44473
5
5
  SHA512:
6
- metadata.gz: 728c6d69adb5ad926a5fea6f852d1d92dd30f5479741a2810454c770abbef939466627752c31b4a335d0e4553568238186e530432382a6de75f62c734adfa4ba
7
- data.tar.gz: cfb8cf388ccf45838213c4ac8b3fe296df9747c00a272c200944f0f2a348c83ea7db3bb2797e6c3f8fc6078b880fbf430b43dbce545134826d9b924463a957b5
6
+ metadata.gz: b0190214a599104891fe8620f3fd04b33001cbcc4c4651a93e8111ac6aacf782f471f336a50bd56a82aa1a87bd68c260d8c3005e0f4122c996c15651542282bb
7
+ data.tar.gz: 7f26566ee130d0a570f8bdd5abe363ebd496ef6ff11bbe8878a6704564a08c3c5ddc72b0aedefcdd125c4146cc57e2bb73cc3c0b2b0eaa0af3fb77ac5d77b4a7
@@ -1,30 +1,30 @@
1
- HISTORY.md
2
- Manifest.txt
3
- README.md
4
- Rakefile
5
- lib/beerdb/deleter.rb
6
- lib/beerdb/models.rb
7
- lib/beerdb/models/beer.rb
8
- lib/beerdb/models/brand.rb
9
- lib/beerdb/models/brewery.rb
10
- lib/beerdb/models/forward.rb
11
- lib/beerdb/models/tag.rb
12
- lib/beerdb/models/world/city.rb
13
- lib/beerdb/models/world/country.rb
14
- lib/beerdb/models/world/region.rb
15
- lib/beerdb/reader.rb
16
- lib/beerdb/reader_file.rb
17
- lib/beerdb/reader_zip.rb
18
- lib/beerdb/readers/beer.rb
19
- lib/beerdb/readers/brewery.rb
20
- lib/beerdb/readers/quick.rb
21
- lib/beerdb/schema.rb
22
- lib/beerdb/serializers/beer.rb
23
- lib/beerdb/serializers/brewery.rb
24
- lib/beerdb/stats.rb
25
- lib/beerdb/version.rb
26
- test/data/great-beers-europe.txt
27
- test/helper.rb
28
- test/test_fixture_matchers.rb
29
- test/test_reader_quick.rb
30
- test/test_values.rb
1
+ HISTORY.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/beerdb/deleter.rb
6
+ lib/beerdb/models.rb
7
+ lib/beerdb/models/beer.rb
8
+ lib/beerdb/models/brand.rb
9
+ lib/beerdb/models/brewery.rb
10
+ lib/beerdb/models/forward.rb
11
+ lib/beerdb/models/tag.rb
12
+ lib/beerdb/models/world/city.rb
13
+ lib/beerdb/models/world/country.rb
14
+ lib/beerdb/models/world/state.rb
15
+ lib/beerdb/reader.rb
16
+ lib/beerdb/reader_file.rb
17
+ lib/beerdb/reader_zip.rb
18
+ lib/beerdb/readers/beer.rb
19
+ lib/beerdb/readers/brewery.rb
20
+ lib/beerdb/readers/quick.rb
21
+ lib/beerdb/schema.rb
22
+ lib/beerdb/serializers/beer.rb
23
+ lib/beerdb/serializers/brewery.rb
24
+ lib/beerdb/stats.rb
25
+ lib/beerdb/version.rb
26
+ test/data/great-beers-europe.txt
27
+ test/helper.rb
28
+ test/test_fixture_matchers.rb
29
+ test/test_reader_quick.rb
30
+ test/test_values.rb
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # beerdb-models - beer.db schema 'n' models for easy (re)use
2
2
 
3
3
 
4
- * home :: [github.com/beerkit/beer.db.models](https://github.com/beerkit/beer.db.models)
5
- * bugs :: [github.com/beerkit/beer.db.models/issues](https://github.com/beerkit/beer.db.models/issues)
4
+ * home :: [github.com/beerkit/beer.db](https://github.com/beerkit/beer.db)
5
+ * bugs :: [github.com/beerkit/beer.db/issues](https://github.com/beerkit/beer.db/issues)
6
6
  * gem :: [rubygems.org/gems/beerdb-models](https://rubygems.org/gems/beerdb-models)
7
7
  * rdoc :: [rubydoc.info/gems/beerdb-models](http://rubydoc.info/gems/beerdb-models)
8
8
  * forum :: [groups.google.com/group/beerdb](https://groups.google.com/group/beerdb)
@@ -92,6 +92,8 @@ wien.breweries
92
92
 
93
93
  ## License
94
94
 
95
+ ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
96
+
95
97
  The `beerdb-models` scripts are dedicated to the public domain.
96
98
  Use it as you please with no restrictions whatsoever.
97
99
 
@@ -99,4 +101,3 @@ Use it as you please with no restrictions whatsoever.
99
101
 
100
102
  Send them along to the [Open Beer & Brewery Database Forum/Mailing List](http://groups.google.com/group/beerdb).
101
103
  Thanks!
102
-
data/Rakefile CHANGED
@@ -3,13 +3,13 @@ require './lib/beerdb/version.rb'
3
3
 
4
4
 
5
5
  Hoe.spec 'beerdb-models' do
6
-
6
+
7
7
  self.version = BeerDb::VERSION
8
-
8
+
9
9
  self.summary = "beerdb-models - beer.db schema 'n' models for easy (re)use"
10
10
  self.description = summary
11
11
 
12
- self.urls = ['https://github.com/beerkit/beer.db.models']
12
+ self.urls = ['https://github.com/beerkit/beer.db']
13
13
 
14
14
  self.author = 'Gerald Bauer'
15
15
  self.email = 'beerdb@googlegroups.com'
@@ -19,13 +19,13 @@ Hoe.spec 'beerdb-models' do
19
19
  self.history_file = 'HISTORY.md'
20
20
 
21
21
  self.extra_deps = [
22
- ['worlddb-models', '>= 2.2.0'], # Note: worlddb-models pulls in all dependencies
22
+ ['worlddb-models', '>= 2.3.4'], # Note: worlddb-models pulls in all dependencies
23
23
  ]
24
24
 
25
25
  self.licenses = ['Public Domain']
26
26
 
27
27
  self.spec_extras = {
28
- required_ruby_version: '>= 1.9.2'
28
+ required_ruby_version: '>= 2.3'
29
29
  }
30
30
 
31
31
  end
@@ -10,7 +10,7 @@ require 'beerdb/version' ## version always goes first
10
10
 
11
11
  require 'beerdb/models/forward'
12
12
  require 'beerdb/models/world/country'
13
- require 'beerdb/models/world/region'
13
+ require 'beerdb/models/world/state'
14
14
  require 'beerdb/models/world/city'
15
15
  require 'beerdb/models/tag'
16
16
  require 'beerdb/models/beer'
@@ -7,12 +7,12 @@ class Beer < ActiveRecord::Base
7
7
 
8
8
  extend TextUtils::TagHelper # will add self.find_tags, self.find_tags_in_attribs!, etc.
9
9
 
10
- # NB: use extend - is_<type>? become class methods e.g. self.is_<type>? for use in
10
+ # Note: use extend - is_<type>? become class methods e.g. self.is_<type>? for use in
11
11
  # self.create_or_update_from_values
12
- extend TextUtils::ValueHelper # e.g. self.is_year?, self.is_region?, self.is_address?, is_taglist? etc.
12
+ extend TextUtils::ValueHelper # e.g. self.is_year?, self.is_state?, self.is_address?, is_taglist? etc.
13
13
 
14
14
  belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
15
- belongs_to :region, :class_name => 'WorldDb::Model::Region', :foreign_key => 'region_id'
15
+ belongs_to :state, :class_name => 'WorldDb::Model::State', :foreign_key => 'state_id'
16
16
  belongs_to :city, :class_name => 'WorldDb::Model::City', :foreign_key => 'city_id'
17
17
 
18
18
  belongs_to :brand, :class_name => 'BeerDb::Model::Brewery', :foreign_key => 'brand_id'
@@ -55,7 +55,7 @@ class Beer < ActiveRecord::Base
55
55
 
56
56
 
57
57
  def as_json_v2( opts={} )
58
- # NB: do NOT overwrite "default" / builtin as_json, thus, lets use as_json_v2
58
+ # Note: do NOT overwrite "default" / builtin as_json, thus, lets use as_json_v2
59
59
  BeerSerializer.new( self ).as_json
60
60
  end
61
61
 
@@ -64,7 +64,7 @@ class Beer < ActiveRecord::Base
64
64
 
65
65
  attribs, more_values = find_key_n_title( values )
66
66
  attribs = attribs.merge( more_attribs )
67
-
67
+
68
68
  # check for optional values
69
69
  Beer.create_or_update_from_attribs( attribs, more_values )
70
70
  end
@@ -74,23 +74,23 @@ class Beer < ActiveRecord::Base
74
74
 
75
75
  # fix: add/configure logger for ActiveRecord!!!
76
76
  logger = LogKernel::Logger.root
77
-
77
+
78
78
  value_tag_keys = []
79
-
79
+
80
80
  ## check for grades (e.g. ***/**/*) in titles (will add attribs[:grade] to hash)
81
81
  ## if grade missing; set default to 4; lets us update overwrite 1,2,3 values on update
82
82
  attribs[ :grade ] ||= 4
83
-
83
+
84
84
  ### check for "default" tags - that is, if present attribs[:tags] remove from hash
85
85
  value_tag_keys += find_tags_in_attribs!( attribs )
86
-
86
+
87
87
  ## check for optional values
88
88
  values.each_with_index do |value,index|
89
89
  if match_country(value) do |country|
90
90
  attribs[ :country_id ] = country.id
91
91
  end
92
- elsif match_region_for_country(value, attribs[:country_id]) do |region|
93
- attribs[ :region_id ] = region.id
92
+ elsif match_state_for_country(value, attribs[:country_id]) do |state|
93
+ attribs[ :state_id ] = state.id
94
94
  end
95
95
  elsif match_city(value) do |city|
96
96
  if city.present?
@@ -103,19 +103,19 @@ class Beer < ActiveRecord::Base
103
103
  elsif match_brewery(value) do |brewery|
104
104
  attribs[ :brewery_id ] = brewery.id
105
105
 
106
- # for easy queries cache city and region ids
107
-
106
+ # for easy queries cache city and state ids
107
+
108
108
  # 1) check if brewery has city - if yes, use it for beer too
109
109
  if brewery.city.present?
110
110
  attribs[ :city_id ] = brewery.city.id
111
111
  end
112
112
 
113
- # 2) check if brewery has city w/ region if yes, use it for beer to
114
- # if not check for region for brewery
115
- if brewery.city.present? && brewery.city.region.present?
116
- attribs[ :region_id ] = brewery.city.region.id
117
- elsif brewery.region.present?
118
- attribs[ :region_id ] = brewery.region.id
113
+ # 2) check if brewery has city w/ state if yes, use it for beer to
114
+ # if not check for state for brewery
115
+ if brewery.city.present? && brewery.city.state.present?
116
+ attribs[ :state_id ] = brewery.city.state.id
117
+ elsif brewery.state.present?
118
+ attribs[ :state_id ] = brewery.state.id
119
119
  end
120
120
  end
121
121
  elsif match_year( value ) do |num| # founded/established year e.g. 1776
@@ -154,27 +154,27 @@ class Beer < ActiveRecord::Base
154
154
  logger.debug "create Beer:"
155
155
  rec = Beer.new
156
156
  end
157
-
157
+
158
158
  logger.debug attribs.to_json
159
159
 
160
160
  rec.update_attributes!( attribs )
161
161
 
162
162
  ##################
163
- # add taggings
163
+ # add taggings
164
164
 
165
165
  ##
166
166
  ## fix: delete all tags first or only add diff?
167
167
  ## fix e.g.
168
168
  ##
169
169
  ## [debug] update Beer 1340-opatsvetlevycepni:
170
- ## [debug] {"title":"Opat Světlé Výčepní","key":"opatsvetlevycepni","country_id":130,"txt":"cz-czech-republic!/beers","grade":4,"brewery_id":839,"city_id":1154,"region_id":241,"abv":4.2,"og":11.0}
170
+ ## [debug] {"title":"Opat Světlé Výčepní","key":"opatsvetlevycepni","country_id":130,"txt":"cz-czech-republic!/beers","grade":4,"brewery_id":839,"city_id":1154,"state_id":241,"abv":4.2,"og":11.0}
171
171
  ## [debug] adding 1 taggings: >>pale lager<<...
172
172
  ## rake aborted!
173
173
  ## ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: columns taggable_id, taggable_type, tag_id are not unique: INSERT INTO "taggings" ("created_at", "tag_id", "taggable_id", "taggable_type", "updated_at") VALUES (?, ?, ?, ?, ?)
174
174
 
175
175
  =begin
176
176
  if value_tag_keys.size > 0
177
-
177
+
178
178
  value_tag_keys.uniq! # remove duplicates
179
179
  logger.debug " adding #{value_tag_keys.size} taggings: >>#{value_tag_keys.join('|')}<<..."
180
180
 
@@ -6,10 +6,10 @@ module BeerDb
6
6
  class Brand < ActiveRecord::Base
7
7
 
8
8
  # NB: use extend - is_<type>? become class methods e.g. self.is_<type>?
9
- extend TextUtils::ValueHelper # e.g. self.find_key_n_title, self.is_year?, self.is_region?, is_address?, is_taglist? etc.
9
+ extend TextUtils::ValueHelper # e.g. self.find_key_n_title, self.is_year?, self.is_state?, is_address?, is_taglist? etc.
10
10
 
11
11
  belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
12
- belongs_to :region, :class_name => 'WorldDb::Model::Region', :foreign_key => 'region_id'
12
+ belongs_to :state, :class_name => 'WorldDb::Model::State', :foreign_key => 'state_id'
13
13
  belongs_to :city, :class_name => 'WorldDb::Model::City', :foreign_key => 'city_id'
14
14
 
15
15
  belongs_to :brewery, :class_name => 'BeerDb::Model::Brewery', :foreign_key => 'brewery_id'
@@ -50,7 +50,7 @@ class Brand < ActiveRecord::Base
50
50
  logger.debug "create Brand:"
51
51
  rec = Brand.new
52
52
  end
53
-
53
+
54
54
  logger.debug attribs.to_json
55
55
 
56
56
  rec.update_attributes!( attribs )
@@ -9,13 +9,13 @@ class Brewery < ActiveRecord::Base
9
9
 
10
10
  # NB: use extend - is_<type>? become class methods e.g. self.is_<type>? for use in
11
11
  # self.create_or_update_from_values
12
- extend TextUtils::ValueHelper # e.g. self.is_year?, self.is_region?, is_address?, is_taglist? etc.
12
+ extend TextUtils::ValueHelper # e.g. self.is_year?, self.is_state?, is_address?, is_taglist? etc.
13
13
  extend TextUtils::AddressHelper # e.g self.normalize_addr, self.find_city_in_addr, etc.
14
14
 
15
15
  self.table_name = 'breweries'
16
16
 
17
17
  belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
18
- belongs_to :region, :class_name => 'WorldDb::Model::Region', :foreign_key => 'region_id'
18
+ belongs_to :state, :class_name => 'WorldDb::Model::State', :foreign_key => 'state_id'
19
19
  belongs_to :city, :class_name => 'WorldDb::Model::City', :foreign_key => 'city_id'
20
20
 
21
21
  has_many :beers, :class_name => 'BeerDb::Model::Beer', :foreign_key => 'brewery_id'
@@ -38,9 +38,9 @@ class Brewery < ActiveRecord::Base
38
38
 
39
39
  def m?() prod_m == true; end
40
40
  def l?() prod_l == true; end
41
-
41
+
42
42
  ## TODO: activerecord supplies brewpub? already? same as attrib; check w/ test case (and remove here)
43
- def brewpub?() brewpub == true; end
43
+ def brewpub?() brewpub == true; end
44
44
 
45
45
 
46
46
 
@@ -80,8 +80,8 @@ class Brewery < ActiveRecord::Base
80
80
  if match_country(value) do |country|
81
81
  new_attributes[ :country_id ] = country.id
82
82
  end
83
- elsif match_region_for_country(value,new_attributes[:country_id]) do |region|
84
- new_attributes[ :region_id ] = region.id
83
+ elsif match_state_for_country(value,new_attributes[:country_id]) do |state|
84
+ new_attributes[ :state_id ] = state.id
85
85
  end
86
86
  elsif match_city(value) do |city|
87
87
  if city.present?
@@ -91,10 +91,10 @@ class Brewery < ActiveRecord::Base
91
91
  logger.warn "city with key #{value[5..-1]} missing - for brewery #{new_attributes[:key]}"
92
92
  end
93
93
 
94
- ## for easy queries: cache region_id (from city)
95
- # - check if city w/ region if yes, use it for brewery too
96
- if city.present? && city.region.present?
97
- new_attributes[ :region_id ] = city.region.id
94
+ ## for easy queries: cache state_id (from city)
95
+ # - check if city w/ state if yes, use it for brewery too
96
+ if city.present? && city.state.present?
97
+ new_attributes[ :state_id ] = city.state.id
98
98
  end
99
99
  end
100
100
  elsif match_year( value ) do |num| # founded/established year e.g. 1776
@@ -131,19 +131,19 @@ class Brewery < ActiveRecord::Base
131
131
  logger.debug "create Brewery:"
132
132
  rec = Brewery.new
133
133
  end
134
-
134
+
135
135
  logger.debug new_attributes.to_json
136
136
 
137
137
  rec.update_attributes!( new_attributes )
138
138
 
139
139
 
140
140
  ##############################
141
- # auto-add city if not present and country n region present
142
-
141
+ # auto-add city if not present and country n state present
142
+
143
143
  if new_attributes[:city_id].blank? &&
144
144
  new_attributes[:country_id].present? &&
145
- new_attributes[:region_id].present?
146
-
145
+ new_attributes[:state_id].present?
146
+
147
147
  country_key = rec.country.key
148
148
 
149
149
  ###
@@ -158,9 +158,9 @@ class Brewery < ActiveRecord::Base
158
158
  ## todo: how to handle nil/empty address lines?
159
159
 
160
160
  city_title = find_city_in_addr( new_attributes[:address], country_key )
161
-
161
+
162
162
  if city_title.present?
163
-
163
+
164
164
  ## for czech - some cleanup
165
165
  ## remove any (remaining) digits in city title
166
166
  city_title = city_title.gsub( /[0-9]/, '' ).strip
@@ -168,7 +168,7 @@ class Brewery < ActiveRecord::Base
168
168
  city_values = [city_title]
169
169
  city_attributes = {
170
170
  country_id: rec.country_id,
171
- region_id: rec.region_id
171
+ state_id: rec.state_id
172
172
  }
173
173
  # todo: add convenience helper create_or_update_from_title
174
174
  city = City.create_or_update_from_values( city_values, city_attributes )
@@ -194,7 +194,7 @@ class Brewery < ActiveRecord::Base
194
194
 
195
195
  ## todo/fix: use strip_inline_comments (e.g #() or (()) - why?? why not??)
196
196
  # - allows titles as usual (use new syntax for inline comments e.g. #() or (()) for example)
197
-
197
+
198
198
  # remove optional longer title part in () e.g. Las Palmas (de Gran Canaria), Palma (de Mallorca)
199
199
  value_brands = TextUtils.strip_subtitles( value_brands )
200
200
 
@@ -206,7 +206,7 @@ class Brewery < ActiveRecord::Base
206
206
  brand_attribs = {
207
207
  brewery_id: rec.id,
208
208
  country_id: rec.country_id,
209
- region_id: rec.region_id,
209
+ state_id: rec.state_id,
210
210
  city_id: rec.city_id
211
211
  }
212
212
 
@@ -253,4 +253,3 @@ end # class Brewery
253
253
 
254
254
  end # module Model
255
255
  end # module BeerDb
256
-
@@ -12,7 +12,7 @@ module BeerDb
12
12
 
13
13
  Continent = WorldDb::Model::Continent
14
14
  Country = WorldDb::Model::Country
15
- Region = WorldDb::Model::Region
15
+ State = WorldDb::Model::State
16
16
  City = WorldDb::Model::City
17
17
 
18
18
  Tag = TagDb::Model::Tag
@@ -29,7 +29,7 @@ module BeerDb
29
29
  ## convenience alias (for better english ;-) )
30
30
  ## lets you use => include Models (instead of include Model)
31
31
  Models = Model
32
-
32
+
33
33
  end # module BeerDb
34
34
 
35
35
 
@@ -43,4 +43,3 @@ module WorldDb
43
43
 
44
44
  end # module Model
45
45
  end # module WorldDb
46
-
@@ -3,12 +3,11 @@
3
3
  module WorldDb
4
4
  module Model
5
5
 
6
- class Region
7
- has_many :beers, :class_name => 'BeerDb::Model::Beer', :foreign_key => 'region_id'
8
- has_many :brands, :class_name => 'BeerDb::Model::Brand', :foreign_key => 'region_id'
9
- has_many :breweries, :class_name => 'BeerDb::Model::Brewery', :foreign_key => 'region_id'
10
- end # class Region
6
+ class State
7
+ has_many :beers, :class_name => 'BeerDb::Model::Beer', :foreign_key => 'state_id'
8
+ has_many :brands, :class_name => 'BeerDb::Model::Brand', :foreign_key => 'state_id'
9
+ has_many :breweries, :class_name => 'BeerDb::Model::Brewery', :foreign_key => 'state_id'
10
+ end # class State
11
11
 
12
12
  end # module Model
13
13
  end # module WorldDb
14
-
@@ -9,24 +9,24 @@ module Matcher
9
9
  match_xxx_for_country( name, 'beers', &blk )
10
10
  end
11
11
 
12
- def match_beers_for_country_n_region( name, &blk )
13
- match_xxx_for_country_n_region( name, 'beers', &blk )
12
+ def match_beers_for_country_n_state( name, &blk )
13
+ match_xxx_for_country_n_state( name, 'beers', &blk )
14
14
  end
15
15
 
16
16
  def match_breweries_for_country( name, &blk )
17
17
  match_xxx_for_country( name, 'breweries', &blk )
18
18
  end
19
19
 
20
- def match_breweries_for_country_n_region( name, &blk )
21
- match_xxx_for_country_n_region( name, 'breweries', &blk )
20
+ def match_breweries_for_country_n_state( name, &blk )
21
+ match_xxx_for_country_n_state( name, 'breweries', &blk )
22
22
  end
23
23
 
24
24
  def match_brewpubs_for_country( name, &blk )
25
25
  match_xxx_for_country( name, 'brewpubs', &blk )
26
26
  end
27
27
 
28
- def match_brewpubs_for_country_n_region( name, &blk )
29
- match_xxx_for_country_n_region( name, 'brewpubs', &blk )
28
+ def match_brewpubs_for_country_n_state( name, &blk )
29
+ match_xxx_for_country_n_state( name, 'brewpubs', &blk )
30
30
  end
31
31
 
32
32
 
@@ -55,20 +55,20 @@ class ReaderBase
55
55
 
56
56
  def load( name )
57
57
 
58
- if match_beers_for_country_n_region( name ) do |country_key, region_key|
59
- load_beers_for_country_n_region( country_key, region_key, name )
58
+ if match_beers_for_country_n_state( name ) do |country_key, state_key|
59
+ load_beers_for_country_n_state( country_key, state_key, name )
60
60
  end
61
61
  elsif match_beers_for_country( name ) do |country_key|
62
62
  load_beers_for_country( country_key, name )
63
63
  end
64
- elsif match_breweries_for_country_n_region( name ) do |country_key, region_key|
65
- load_breweries_for_country_n_region( country_key, region_key, name )
64
+ elsif match_breweries_for_country_n_state( name ) do |country_key, state_key|
65
+ load_breweries_for_country_n_state( country_key, state_key, name )
66
66
  end
67
67
  elsif match_breweries_for_country( name ) do |country_key|
68
68
  load_breweries_for_country( country_key, name )
69
69
  end
70
- elsif match_brewpubs_for_country_n_region( name ) do |country_key, region_key|
71
- load_breweries_for_country_n_region( country_key, region_key, name, brewpub: true )
70
+ elsif match_brewpubs_for_country_n_state( name ) do |country_key, state_key|
71
+ load_breweries_for_country_n_state( country_key, state_key, name, brewpub: true )
72
72
  end
73
73
  elsif match_brewpubs_for_country( name ) do |country_key|
74
74
  load_breweries_for_country( country_key, name, brewpub: true )
@@ -80,19 +80,20 @@ class ReaderBase
80
80
  end
81
81
 
82
82
 
83
- def load_beers_for_country_n_region( country_key, region_key, name, more_attribs={} )
84
- country = Country.find_by_key!( country_key )
83
+ def load_beers_for_country_n_state( country_key, state_key, name, more_attribs={} )
84
+ country = Country.find_by!( key: country_key )
85
85
  logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
86
86
  more_attribs[ :country_id ] = country.id
87
87
 
88
- # NB: region lookup requires country id (region key only unique for country)
89
- region = Region.find_by_key_and_country_id( region_key, country.id )
90
- if region.nil?
91
- # note: allow unknown region keys; issue warning n skip region
92
- logger.warn "Region w/ key >#{region_key}< not found; skip adding region"
88
+ # Note: state lookup requires country id (state key only unique for country)
89
+ ## check: was find_by_key_and_country_id
90
+ state = State.find_by( key: state_key, country_id: country.id )
91
+ if state.nil?
92
+ # note: allow unknown state keys; issue warning n skip state
93
+ logger.warn "State w/ key >#{state_key}< not found; skip adding state"
93
94
  else
94
- logger.debug "Region #{region.key} >#{region.title}<"
95
- more_attribs[ :region_id ] = region.id
95
+ logger.debug "State #{state.key} >#{state.title}<"
96
+ more_attribs[ :state_id ] = state.id
96
97
  end
97
98
 
98
99
  more_attribs[ :txt ] = name # store source ref
@@ -101,7 +102,7 @@ class ReaderBase
101
102
  end
102
103
 
103
104
  def load_beers_for_country( country_key, name, more_attribs={} )
104
- country = Country.find_by_key!( country_key )
105
+ country = Country.find_by!( key: country_key )
105
106
  logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
106
107
 
107
108
  more_attribs[ :country_id ] = country.id
@@ -112,20 +113,21 @@ class ReaderBase
112
113
  end
113
114
 
114
115
 
115
- def load_breweries_for_country_n_region( country_key, region_key, name, more_attribs={} )
116
- country = Country.find_by_key!( country_key )
116
+ def load_breweries_for_country_n_state( country_key, state_key, name, more_attribs={} )
117
+ country = Country.find_by!( key: country_key )
117
118
  logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
118
119
 
119
120
  more_attribs[ :country_id ] = country.id
120
121
 
121
- # note: region lookup requires country id (region key only unique for country)
122
- region = Region.find_by_key_and_country_id( region_key, country.id )
123
- if region.nil?
124
- # note: allow unknown region keys; issue warning n skip region
125
- logger.warn "Region w/ key >#{region_key}< not found; skip adding region"
122
+ # note: state lookup requires country id (state key only unique for country)
123
+ ## was: State.find_by_key_and_country_id( state_key, country.id )
124
+ state = State.find_by( key: state_key, country_id: country.id )
125
+ if state.nil?
126
+ # note: allow unknown state keys; issue warning n skip state
127
+ logger.warn "State w/ key >#{state_key}< not found; skip adding state"
126
128
  else
127
- logger.debug "Region #{region.key} >#{region.title}<"
128
- more_attribs[ :region_id ] = region.id
129
+ logger.debug "State #{state.key} >#{state.title}<"
130
+ more_attribs[ :state_id ] = state.id
129
131
  end
130
132
 
131
133
  more_attribs[ :txt ] = name # store source ref
@@ -134,7 +136,7 @@ class ReaderBase
134
136
  end
135
137
 
136
138
  def load_breweries_for_country( country_key, name, more_attribs={} )
137
- country = Country.find_by_key!( country_key )
139
+ country = Country.find_by!( key: country_key )
138
140
  logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
139
141
 
140
142
  more_attribs[ :country_id ] = country.id
@@ -29,7 +29,7 @@ class BeerReader
29
29
 
30
30
  def self.from_string( text, more_attribs={} )
31
31
  BeerReader.new( text, more_attribs )
32
- end
32
+ end
33
33
 
34
34
  def initialize( text, more_attribs={} )
35
35
  ## todo/fix: how to add opts={} ???
@@ -44,12 +44,12 @@ class BeerReader
44
44
 
45
45
  ### todo: cleanup - check if [] works for build_title...
46
46
  # better cleaner way ???
47
- if @more_attribs[:region_id].present?
48
- known_breweries_source = Brewery.where( region_id: @more_attribs[:region_id] )
47
+ if @more_attribs[:state_id].present?
48
+ known_breweries_source = Brewery.where( state_id: @more_attribs[:state_id] )
49
49
  elsif @more_attribs[:country_id].present?
50
50
  known_breweries_source = Brewery.where( country_id: @more_attribs[:country_id] )
51
51
  else
52
- logger.warn "no region or country specified; use empty brewery ary for header mapper"
52
+ logger.warn "no state or country specified; use empty brewery ary for header mapper"
53
53
  known_breweries_source = []
54
54
  end
55
55
 
@@ -61,7 +61,7 @@ class BeerReader
61
61
  ## note: check for header attrib; if present remove
62
62
  ### todo: cleanup code later
63
63
  ## fix: add to new_attributes hash instead of values ary
64
- ## - fix: match_brewery() move region,city code out of values loop for reuse at the end
64
+ ## - fix: match_brewery() move state,city code out of values loop for reuse at the end
65
65
  if new_attributes[:header].present?
66
66
  brewery_line = new_attributes[:header].dup # note: make sure we make a copy; will use in-place string ops
67
67
  new_attributes.delete(:header) ## note: do NOT forget to remove from hash!
@@ -3,9 +3,11 @@
3
3
  module BeerDb
4
4
 
5
5
 
6
- class CreateDb < ActiveRecord::Migration
6
+ class CreateDb
7
+
7
8
 
8
9
  def up
10
+ ActiveRecord::Schema.define do
9
11
 
10
12
  create_table :beers do |t|
11
13
  t.string :key, null: false # import/export key
@@ -26,7 +28,7 @@ create_table :beers do |t|
26
28
  ## add t.boolean :lite flag ??
27
29
  t.decimal :kcal, precision: 10, scale: 2 # kcal/100ml e.g. 45.0 kcal/100ml
28
30
 
29
- ## check: why decimal and not float?
31
+ ## check: why decimal and not float?
30
32
  t.decimal :abv, precision: 10, scale: 2 # Alcohol by volume (abbreviated as ABV, abv, or alc/vol) e.g. 4.9 %
31
33
  t.decimal :og, precision: 10, scale: 2 # malt extract (original gravity) in plato
32
34
  t.integer :srm # color in srm
@@ -73,7 +75,7 @@ create_table :beers do |t|
73
75
 
74
76
 
75
77
  t.references :country, null: false
76
- t.references :region # optional
78
+ t.references :state # optional
77
79
  t.references :city # optional
78
80
 
79
81
  t.timestamps
@@ -89,7 +91,7 @@ create_table :brands do |t| # beer families (sharing same name e.g. brand)
89
91
  t.integer :since
90
92
 
91
93
  ## scope of brand (global/intern'l/national/regional/local) ??
92
- t.boolean :global, null: false, default: false
94
+ t.boolean :global, null: false, default: false
93
95
  t.boolean :internl, null: false, default: false
94
96
  t.boolean :national, null: false, default: false
95
97
  t.boolean :regional, null: false, default: false
@@ -108,7 +110,7 @@ create_table :brands do |t| # beer families (sharing same name e.g. brand)
108
110
  t.references :brewery # optional (for now)
109
111
 
110
112
  t.references :country, null: false
111
- t.references :region # optional
113
+ t.references :state # optional
112
114
  t.references :city # optional
113
115
 
114
116
  t.timestamps
@@ -124,7 +126,7 @@ create_table :breweries do |t|
124
126
  ## fix: add flag for ca./about boolean opened_guess / opened_est / opened_??
125
127
  ## ca. / about 1010 marker e.g t.boolean : opened_est (for estimate) or similar!!!
126
128
  ## renamed to founded to since
127
- ## t.integer :founded # year founded/established - todo/fix: rename to since?
129
+ ## t.integer :founded # year founded/established - todo/fix: rename to since?
128
130
  t.integer :closed # optional; year brewery closed
129
131
 
130
132
  ## todo: add optional parent brewery (owned_by) ???
@@ -177,18 +179,15 @@ create_table :breweries do |t|
177
179
  # (or better use has many parents w/ percentage of ownership; might not be 100%)
178
180
 
179
181
  t.references :country, null: false
180
- t.references :region # optional
182
+ t.references :state # optional
181
183
  t.references :city # optional
182
-
184
+
183
185
  t.timestamps
184
186
  end
185
187
 
188
+ end # Schema.define
186
189
  end # method up
187
190
 
188
- def down
189
- raise ActiveRecord::IrreversibleMigration
190
- end
191
-
192
191
 
193
192
  end # class CreateDb
194
193
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  module BeerDb
4
4
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
5
- MINOR = 0
6
- PATCH = 1
5
+ MINOR = 1
6
+ PATCH = 0
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
@@ -18,4 +18,3 @@ module BeerDb
18
18
  "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
19
19
  end
20
20
  end # module BeerDb
21
-
@@ -11,7 +11,7 @@ require 'beerdb/models'
11
11
 
12
12
 
13
13
  Country = WorldDb::Model::Country
14
- Region = WorldDb::Model::Region
14
+ State = WorldDb::Model::State
15
15
 
16
16
  ## todo: get all models aliases (e.g. from console script)
17
17
 
@@ -46,18 +46,18 @@ def fillup_in_memory_db
46
46
  ## add some counties
47
47
 
48
48
  at = Country.create!( key: 'at', title: 'Austria', code: 'AUT', pop: 0, area: 0 )
49
- Region.create!( key: 'w', title: 'Wien', country_id: at.id )
50
-
49
+ State.create!( key: 'w', title: 'Wien', country_id: at.id )
50
+
51
51
  de = Country.create!( key: 'de', title: 'Germany', code: 'DEU', pop: 0, area: 0 )
52
- Region.create!( key: 'by', title: 'Bayern', country_id: de.id )
53
-
52
+ State.create!( key: 'by', title: 'Bayern', country_id: de.id )
53
+
54
54
  end
55
55
 
56
56
  setup_in_memory_db()
57
57
  fillup_in_memory_db()
58
58
 
59
- AT = Country.find_by_key!( 'at' )
60
- W = Region.find_by_key!( 'w' )
59
+ AT = Country.find_by!( key: 'at' )
60
+ W = State.find_by!( key: 'w' )
61
61
 
62
- DE = Country.find_by_key!( 'de' )
63
- BY = Region.find_by_key!( 'by' )
62
+ DE = Country.find_by!( key: 'de' )
63
+ BY = State.find_by!( key: 'by' )
@@ -46,7 +46,7 @@ class TestFixtureMatchers < MiniTest::Test
46
46
  end # method test_country
47
47
 
48
48
 
49
- def test_country_n_region
49
+ def test_country_n_state
50
50
 
51
51
  beers_at = [
52
52
  'europe/at-austria/w-wien/beers',
@@ -57,9 +57,9 @@ class TestFixtureMatchers < MiniTest::Test
57
57
  ]
58
58
 
59
59
  beers_at.each do |name|
60
- found = match_beers_for_country_n_region( name ) do |country_key,region_key|
60
+ found = match_beers_for_country_n_state( name ) do |country_key,state_key|
61
61
  assert( country_key == 'at')
62
- assert( region_key == 'w' )
62
+ assert( state_key == 'w' )
63
63
  end
64
64
  assert( found == true )
65
65
  end
@@ -73,13 +73,13 @@ class TestFixtureMatchers < MiniTest::Test
73
73
  ]
74
74
 
75
75
  breweries_at.each do |name|
76
- found = match_breweries_for_country_n_region( name ) do |country_key,region_key|
76
+ found = match_breweries_for_country_n_state( name ) do |country_key,state_key|
77
77
  assert( country_key == 'at')
78
- assert( region_key == 'w' )
78
+ assert( state_key == 'w' )
79
79
  end
80
80
  assert( found == true )
81
81
  end
82
- end # method test_country_n_region
82
+ end # method test_country_n_state
83
83
 
84
84
 
85
- end # class TestFixtureMatchers
85
+ end # class TestFixtureMatchers
@@ -37,7 +37,7 @@ class TestValues < MiniTest::Test
37
37
  assert_equal beer.id, beer2.id
38
38
 
39
39
  assert_equal beer.title, values[0]
40
- assert_equal beer.country_id, AT.id
40
+ assert_equal beer.country_id, AT.id
41
41
  assert_equal beer.country.title, AT.title
42
42
  assert_equal beer.abv, 5.2
43
43
  assert_equal beer.og, 11.8
@@ -64,7 +64,7 @@ class TestValues < MiniTest::Test
64
64
  country_id: AT.id
65
65
  }
66
66
 
67
-
67
+
68
68
  by = Brewery.create_or_update_from_values( values, more_attribs )
69
69
 
70
70
  by2 = Brewery.find_by_key!( key )
@@ -122,7 +122,7 @@ class TestValues < MiniTest::Test
122
122
 
123
123
  ## fix!!!!!!!!: use different brewery! use one w/ synonyms
124
124
  ###
125
-
125
+
126
126
  # ottakringer, Ottakringer Brauerei, 1838, www.ottakringer.at, WI, city:wien, 1160 Wien // Ottakringer Platz 1
127
127
  # brands: Ottakringer
128
128
 
@@ -170,7 +170,7 @@ class TestValues < MiniTest::Test
170
170
 
171
171
  more_attribs = {
172
172
  country_id: AT.id,
173
- region_id: W.id
173
+ state_id: W.id
174
174
  }
175
175
 
176
176
  by = Brewery.create_or_update_from_values( values, more_attribs )
@@ -193,7 +193,7 @@ class TestValues < MiniTest::Test
193
193
  assert( br.brewery_id == by.id )
194
194
  assert( br.brewery.title == by.title )
195
195
  assert( br.country_id == by.country_id )
196
-
196
+
197
197
  # todo: check for auto-created city
198
198
  assert( by.city.title == 'Wien' )
199
199
  end
@@ -201,12 +201,12 @@ class TestValues < MiniTest::Test
201
201
 
202
202
  def test_load_brewery_values_w_city_de
203
203
 
204
- # hofbraeu, Hofbräu München, 1589, www.hofbraeu-muenchen.de, 81829 München // Hofbräuallee 1
204
+ # hofbraeu, Hofbräu München, 1589, www.hofbraeu-muenchen.de, 81829 München // Hofbräuallee 1
205
205
 
206
206
  key = 'hofbraeu'
207
207
 
208
208
  values = [
209
- key,
209
+ key,
210
210
  'Hofbräu München',
211
211
  '1589',
212
212
  'www.hofbraeu-muenchen.de',
@@ -216,7 +216,7 @@ class TestValues < MiniTest::Test
216
216
 
217
217
  more_attribs = {
218
218
  country_id: DE.id,
219
- region_id: BY.id
219
+ state_id: BY.id
220
220
  }
221
221
 
222
222
  by = Brewery.create_or_update_from_values( values, more_attribs )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beerdb-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-28 00:00:00.000000000 Z
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: worlddb-models
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0
19
+ version: 2.3.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.0
26
+ version: 2.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.13'
47
+ version: '3.16'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.13'
54
+ version: '3.16'
55
55
  description: beerdb-models - beer.db schema 'n' models for easy (re)use
56
56
  email: beerdb@googlegroups.com
57
57
  executables: []
@@ -61,7 +61,6 @@ extra_rdoc_files:
61
61
  - Manifest.txt
62
62
  - README.md
63
63
  files:
64
- - ".gemtest"
65
64
  - HISTORY.md
66
65
  - Manifest.txt
67
66
  - README.md
@@ -75,7 +74,7 @@ files:
75
74
  - lib/beerdb/models/tag.rb
76
75
  - lib/beerdb/models/world/city.rb
77
76
  - lib/beerdb/models/world/country.rb
78
- - lib/beerdb/models/world/region.rb
77
+ - lib/beerdb/models/world/state.rb
79
78
  - lib/beerdb/reader.rb
80
79
  - lib/beerdb/reader_file.rb
81
80
  - lib/beerdb/reader_zip.rb
@@ -92,7 +91,7 @@ files:
92
91
  - test/test_fixture_matchers.rb
93
92
  - test/test_reader_quick.rb
94
93
  - test/test_values.rb
95
- homepage: https://github.com/beerkit/beer.db.models
94
+ homepage: https://github.com/beerkit/beer.db
96
95
  licenses:
97
96
  - Public Domain
98
97
  metadata: {}
@@ -106,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
105
  requirements:
107
106
  - - ">="
108
107
  - !ruby/object:Gem::Version
109
- version: 1.9.2
108
+ version: '2.3'
110
109
  required_rubygems_version: !ruby/object:Gem::Requirement
111
110
  requirements:
112
111
  - - ">="
@@ -114,11 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
113
  version: '0'
115
114
  requirements: []
116
115
  rubyforge_project:
117
- rubygems_version: 2.4.2
116
+ rubygems_version: 2.5.2
118
117
  signing_key:
119
118
  specification_version: 4
120
119
  summary: beerdb-models - beer.db schema 'n' models for easy (re)use
121
- test_files:
122
- - test/test_values.rb
123
- - test/test_reader_quick.rb
124
- - test/test_fixture_matchers.rb
120
+ test_files: []
data/.gemtest DELETED
File without changes