beerdb 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.
- data/Manifest.txt +3 -0
- data/Rakefile +2 -2
- data/lib/beerdb/console.rb +79 -0
- data/lib/beerdb/models/beer.rb +6 -0
- data/lib/beerdb/models/brewery.rb +6 -0
- data/lib/beerdb/models/city.rb +2 -2
- data/lib/beerdb/models/forward.rb +4 -0
- data/lib/beerdb/models/region.rb +9 -0
- data/lib/beerdb/models/tag.rb +9 -0
- data/lib/beerdb/reader.rb +190 -8
- data/lib/beerdb/schema.rb +40 -5
- data/lib/beerdb/version.rb +1 -1
- data/lib/beerdb.rb +2 -0
- metadata +15 -12
data/Manifest.txt
CHANGED
@@ -6,12 +6,15 @@ bin/beerdb
|
|
6
6
|
lib/beerdb.rb
|
7
7
|
lib/beerdb/cli/main.rb
|
8
8
|
lib/beerdb/cli/opts.rb
|
9
|
+
lib/beerdb/console.rb
|
9
10
|
lib/beerdb/deleter.rb
|
10
11
|
lib/beerdb/models/beer.rb
|
11
12
|
lib/beerdb/models/brewery.rb
|
12
13
|
lib/beerdb/models/city.rb
|
13
14
|
lib/beerdb/models/country.rb
|
14
15
|
lib/beerdb/models/forward.rb
|
16
|
+
lib/beerdb/models/region.rb
|
17
|
+
lib/beerdb/models/tag.rb
|
15
18
|
lib/beerdb/reader.rb
|
16
19
|
lib/beerdb/schema.rb
|
17
20
|
lib/beerdb/stats.rb
|
data/Rakefile
CHANGED
@@ -67,7 +67,7 @@ namespace :beerdb do
|
|
67
67
|
require 'beerdb'
|
68
68
|
require 'logutils/db'
|
69
69
|
|
70
|
-
LogUtils::Logger.root.level = :
|
70
|
+
LogUtils::Logger.root.level = :debug
|
71
71
|
|
72
72
|
pp DB_CONFIG
|
73
73
|
ActiveRecord::Base.establish_connection( DB_CONFIG )
|
@@ -85,7 +85,7 @@ namespace :beerdb do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
task :importbeer => :env do
|
88
|
-
BeerDb.read_setup( 'setups/
|
88
|
+
BeerDb.read_setup( 'setups/at', '../beer.db' )
|
89
89
|
BeerDb.tables
|
90
90
|
end
|
91
91
|
|
@@ -0,0 +1,79 @@
|
|
1
|
+
## for use to run with interactive ruby (irb)
|
2
|
+
## e.g. irb -r sportdb/console
|
3
|
+
|
4
|
+
require 'beerdb'
|
5
|
+
|
6
|
+
# some ruby stdlibs
|
7
|
+
|
8
|
+
require 'logger'
|
9
|
+
require 'pp' # pretty printer
|
10
|
+
require 'uri'
|
11
|
+
require 'json'
|
12
|
+
require 'yaml'
|
13
|
+
|
14
|
+
|
15
|
+
## shortcuts for models
|
16
|
+
|
17
|
+
Beer = BeerDb::Models::Beer
|
18
|
+
Brewery = BeerDb::Models::Brewery
|
19
|
+
|
20
|
+
Tag = WorldDb::Models::Tag
|
21
|
+
Tagging = WorldDb::Models::Tagging
|
22
|
+
Continent = WorldDb::Models::Continent
|
23
|
+
Country = WorldDb::Models::Country
|
24
|
+
Region = WorldDb::Models::Region
|
25
|
+
City = WorldDb::Models::City
|
26
|
+
Prop = WorldDb::Models::Prop
|
27
|
+
|
28
|
+
## connect to db
|
29
|
+
|
30
|
+
DB_CONFIG = {
|
31
|
+
adapter: 'sqlite3',
|
32
|
+
database: 'beer.db'
|
33
|
+
}
|
34
|
+
|
35
|
+
pp DB_CONFIG
|
36
|
+
ActiveRecord::Base.establish_connection( DB_CONFIG )
|
37
|
+
|
38
|
+
## test drive
|
39
|
+
|
40
|
+
puts "Welcome to beer.db, version #{BeerDb::VERSION} (world.db, version #{WorldDb::VERSION})!"
|
41
|
+
|
42
|
+
BeerDb.tables
|
43
|
+
|
44
|
+
puts "Ready."
|
45
|
+
|
46
|
+
## add some predefined shortcuts
|
47
|
+
|
48
|
+
##### some countries
|
49
|
+
|
50
|
+
AT = Country.find_by_key( 'at' )
|
51
|
+
DE = Country.find_by_key( 'de' )
|
52
|
+
EN = Country.find_by_key( 'en' )
|
53
|
+
|
54
|
+
US = Country.find_by_key( 'us' )
|
55
|
+
MX = Country.find_by_key( 'mx' )
|
56
|
+
|
57
|
+
### some cities
|
58
|
+
|
59
|
+
WIEN = City.find_by_key( 'wien' )
|
60
|
+
|
61
|
+
### some regions
|
62
|
+
|
63
|
+
NO = Region.find_by_key_and_country_id( 'no', AT.id ) # at - niederoesterreich
|
64
|
+
OO = Region.find_by_key_and_country_id( 'oo', AT.id ) # at - oberoesterreich
|
65
|
+
|
66
|
+
#### some beers
|
67
|
+
|
68
|
+
## to be done
|
69
|
+
|
70
|
+
|
71
|
+
### some breweries
|
72
|
+
|
73
|
+
OTTAKRINGER = Brewery.find_by_key( 'ottakringer' )
|
74
|
+
SCHWECHAT = Brewery.find_by_key( 'schwechat' )
|
75
|
+
|
76
|
+
|
77
|
+
## turn on activerecord logging to console
|
78
|
+
|
79
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
data/lib/beerdb/models/beer.rb
CHANGED
@@ -3,8 +3,14 @@ module BeerDb::Models
|
|
3
3
|
class Beer < ActiveRecord::Base
|
4
4
|
|
5
5
|
belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
|
6
|
+
belongs_to :region, :class_name => 'WorldDb::Models::Region', :foreign_key => 'region_id'
|
6
7
|
belongs_to :city, :class_name => 'WorldDb::Models::City', :foreign_key => 'city_id'
|
7
8
|
|
9
|
+
belongs_to :brewery, :class_name => 'BeerDb::Models::Brewery', :foreign_key => 'brewery_id'
|
10
|
+
|
11
|
+
has_many :taggings, :as => :taggable, :class_name => 'WorldDb::Models::Tagging'
|
12
|
+
has_many :tags, :through => :taggings, :class_name => 'WorldDb::Models::Tag'
|
13
|
+
|
8
14
|
end # class Beer
|
9
15
|
|
10
16
|
|
@@ -5,8 +5,14 @@ class Brewery < ActiveRecord::Base
|
|
5
5
|
self.table_name = 'breweries'
|
6
6
|
|
7
7
|
belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
|
8
|
+
belongs_to :region, :class_name => 'WorldDb::Models::Region', :foreign_key => 'region_id'
|
8
9
|
belongs_to :city, :class_name => 'WorldDb::Models::City', :foreign_key => 'city_id'
|
9
10
|
|
11
|
+
has_many :beers, :class_name => 'BeerDb::Models::Beer', :foreign_key => 'brewery_id'
|
12
|
+
|
13
|
+
has_many :taggings, :as => :taggable, :class_name => 'WorldDb::Models::Tagging'
|
14
|
+
has_many :tags, :through => :taggings, :class_name => 'WorldDb::Models::Tag'
|
15
|
+
|
10
16
|
end # class Brewery
|
11
17
|
|
12
18
|
|
data/lib/beerdb/models/city.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module WorldDb::Models
|
2
2
|
|
3
3
|
class City
|
4
|
-
has_many :beers, :class_name => 'BeerDb::Models::Beer', :foreign_key => '
|
5
|
-
has_many :breweries, :class_name => 'BeerDb::Models::Brewery', :foreign_key => '
|
4
|
+
has_many :beers, :class_name => 'BeerDb::Models::Beer', :foreign_key => 'city_id'
|
5
|
+
has_many :breweries, :class_name => 'BeerDb::Models::Brewery', :foreign_key => 'city_id'
|
6
6
|
end # class Country
|
7
7
|
|
8
8
|
end # module WorldDb::Models
|
@@ -9,6 +9,10 @@ module BeerDb::Models
|
|
9
9
|
Country = WorldDb::Models::Country
|
10
10
|
Region = WorldDb::Models::Region
|
11
11
|
City = WorldDb::Models::City
|
12
|
+
|
13
|
+
Tag = WorldDb::Models::Tag
|
14
|
+
Tagging = WorldDb::Models::Tagging
|
15
|
+
|
12
16
|
Prop = WorldDb::Models::Prop
|
13
17
|
|
14
18
|
class Beer < ActiveRecord::Base ; end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
module WorldDb::Models
|
3
|
+
|
4
|
+
class Region
|
5
|
+
has_many :beers, :class_name => 'BeerDb::Models::Beer', :foreign_key => 'region_id'
|
6
|
+
has_many :breweries, :class_name => 'BeerDb::Models::Brewery', :foreign_key => 'region_id'
|
7
|
+
end # class Region
|
8
|
+
|
9
|
+
end # module WorldDb::Models
|
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
module WorldDb::Models
|
3
|
+
|
4
|
+
class Tag
|
5
|
+
has_many :beers, :through => :taggings, :source => :taggable, :source_type => 'BeerDb::Models::Beer', :class_name => 'BeerDb::Models::Beer'
|
6
|
+
has_many :breweries, :through => :taggings, :source => :taggable, :source_type => 'BeerDb::Models::Brewery', :class_name => 'BeerDb::Models::Brewery'
|
7
|
+
end # class Country
|
8
|
+
|
9
|
+
end # module WorldDb::Models
|
data/lib/beerdb/reader.rb
CHANGED
@@ -68,6 +68,9 @@ class Reader
|
|
68
68
|
if name =~ /\/([a-z]{2})\/beers/
|
69
69
|
## auto-add required country code (from folder structure)
|
70
70
|
load_beers( $1, name )
|
71
|
+
elsif name =~ /\/([a-z]{2})\/breweries/
|
72
|
+
## auto-add required country code (from folder structure)
|
73
|
+
load_breweries( $1, name )
|
71
74
|
else
|
72
75
|
logger.error "unknown beer.db fixture type >#{name}<"
|
73
76
|
# todo/fix: exit w/ error
|
@@ -86,15 +89,150 @@ class Reader
|
|
86
89
|
logger.info "parsing data '#{name}' (#{path})..."
|
87
90
|
|
88
91
|
reader = ValuesReader.new( path, more_values )
|
89
|
-
|
92
|
+
|
90
93
|
load_beers_worker( reader )
|
91
94
|
|
92
95
|
Prop.create_from_fixture!( name, path )
|
93
96
|
end
|
94
97
|
|
95
98
|
|
99
|
+
def load_breweries( country_key, name, more_values={} )
|
100
|
+
country = Country.find_by_key!( country_key )
|
101
|
+
logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
|
102
|
+
|
103
|
+
more_values[ :country_id ] = country.id
|
104
|
+
|
105
|
+
path = "#{include_path}/#{name}.txt"
|
106
|
+
|
107
|
+
logger.info "parsing data '#{name}' (#{path})..."
|
108
|
+
|
109
|
+
reader = ValuesReader.new( path, more_values )
|
110
|
+
|
111
|
+
load_breweries_worker( reader )
|
112
|
+
|
113
|
+
Prop.create_from_fixture!( name, path )
|
114
|
+
end
|
115
|
+
|
116
|
+
|
96
117
|
private
|
97
118
|
|
119
|
+
def load_breweries_worker( reader )
|
120
|
+
|
121
|
+
## NB: assumes active activerecord db connection
|
122
|
+
|
123
|
+
reader.each_line do |attribs, values|
|
124
|
+
|
125
|
+
|
126
|
+
### todo/fix: move this code to model (lets us reuse it)
|
127
|
+
|
128
|
+
value_tag_keys = []
|
129
|
+
|
130
|
+
### check for "default" tags - that is, if present attribs[:tags] remove from hash
|
131
|
+
|
132
|
+
if attribs[:tags].present?
|
133
|
+
more_tag_keys = attribs[:tags].split('|')
|
134
|
+
attribs.delete(:tags)
|
135
|
+
|
136
|
+
## unify; replace _ w/ space; remove leading n trailing whitespace
|
137
|
+
more_tag_keys = more_tag_keys.map do |key|
|
138
|
+
key = key.gsub( '_', ' ' )
|
139
|
+
key = key.strip
|
140
|
+
key
|
141
|
+
end
|
142
|
+
|
143
|
+
value_tag_keys += more_tag_keys
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
## check for optional values
|
148
|
+
values.each_with_index do |value,index|
|
149
|
+
if value =~ /^country:/ ## country:
|
150
|
+
value_country_key = value[8..-1] ## cut off country: prefix
|
151
|
+
value_country = Country.find_by_key!( value_country_key )
|
152
|
+
attribs[ :country_id ] = value_country.id
|
153
|
+
elsif value =~ /^region:/ ## region:
|
154
|
+
value_region_key = value[7..-1] ## cut off region: prefix
|
155
|
+
value_region = Region.find_by_key_and_country_id!( value_region_key, attribs[:country_id] )
|
156
|
+
attribs[ :region_id ] = value_region.id
|
157
|
+
elsif value =~ /^[A-Z]{1,2}$/ ## assume region code e.g. TX or N
|
158
|
+
value_region = Region.find_by_key_and_country_id!( value.downcase, attribs[:country_id] )
|
159
|
+
attribs[ :region_id ] = value_region.id
|
160
|
+
elsif value =~ /^city:/ ## city:
|
161
|
+
value_city_key = value[5..-1] ## cut off city: prefix
|
162
|
+
value_city = City.find_by_key( value_city_key )
|
163
|
+
if value_city.present?
|
164
|
+
attribs[ :city_id ] = value_city.id
|
165
|
+
else
|
166
|
+
## todo/fix: add strict mode flag - fail w/ exit 1 in strict mode
|
167
|
+
logger.warn "city with key #{value_city_key} missing"
|
168
|
+
end
|
169
|
+
|
170
|
+
## for easy queries: cache region_id (from city)
|
171
|
+
# - check if city w/ region if yes, use it for brewery too
|
172
|
+
if value_city.present? && value_city.region.present?
|
173
|
+
attribs[ :region_id ] = value_city.region.id
|
174
|
+
end
|
175
|
+
elsif value =~ /^[0-9]{4}$/ # founded/established year e.g. 1776
|
176
|
+
attribs[ :founded ] = value.to_i
|
177
|
+
elsif value =~ /\/{2}/ # if value includes // assume address e.g. 3970 Weitra // Sparkasseplatz 160
|
178
|
+
attribs[ :address ] = value
|
179
|
+
elsif (values.size==(index+1)) && value =~ /^[a-z0-9\|_ ]+$/ # tags must be last entry
|
180
|
+
|
181
|
+
logger.debug " found tags: >>#{value}<<"
|
182
|
+
|
183
|
+
tag_keys = value.split('|')
|
184
|
+
|
185
|
+
## unify; replace _ w/ space; remove leading n trailing whitespace
|
186
|
+
tag_keys = tag_keys.map do |key|
|
187
|
+
key = key.gsub( '_', ' ' )
|
188
|
+
key = key.strip
|
189
|
+
key
|
190
|
+
end
|
191
|
+
|
192
|
+
value_tag_keys += tag_keys
|
193
|
+
else
|
194
|
+
# issue warning: unknown type for value
|
195
|
+
logger.warn "unknown type for value >#{value}<"
|
196
|
+
end
|
197
|
+
end # each value
|
198
|
+
|
199
|
+
rec = Brewery.find_by_key( attribs[ :key ] )
|
200
|
+
|
201
|
+
if rec.present?
|
202
|
+
logger.debug "update Brewery #{rec.id}-#{rec.key}:"
|
203
|
+
else
|
204
|
+
logger.debug "create Brewery:"
|
205
|
+
rec = Brewery.new
|
206
|
+
end
|
207
|
+
|
208
|
+
logger.debug attribs.to_json
|
209
|
+
|
210
|
+
rec.update_attributes!( attribs )
|
211
|
+
|
212
|
+
##################
|
213
|
+
## add taggings
|
214
|
+
|
215
|
+
if value_tag_keys.size > 0
|
216
|
+
|
217
|
+
value_tag_keys.uniq! # remove duplicates
|
218
|
+
logger.debug " adding #{value_tag_keys.size} taggings: >>#{value_tag_keys.join('|')}<<..."
|
219
|
+
|
220
|
+
### fix/todo: check tag_ids and only update diff (add/remove ids)
|
221
|
+
|
222
|
+
value_tag_keys.each do |key|
|
223
|
+
tag = Tag.find_by_key( key )
|
224
|
+
if tag.nil? # create tag if it doesn't exit
|
225
|
+
logger.debug " creating tag >#{key}<"
|
226
|
+
tag = Tag.create!( key: key )
|
227
|
+
end
|
228
|
+
rec.tags << tag
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end # each_line
|
233
|
+
|
234
|
+
end # method load_breweries_worker
|
235
|
+
|
98
236
|
|
99
237
|
def load_beers_worker( reader )
|
100
238
|
|
@@ -102,6 +240,8 @@ private
|
|
102
240
|
##
|
103
241
|
|
104
242
|
reader.each_line do |attribs, values|
|
243
|
+
|
244
|
+
### todo/fix: move this code to model (lets us reuse it)
|
105
245
|
|
106
246
|
value_tag_keys = []
|
107
247
|
|
@@ -111,7 +251,7 @@ private
|
|
111
251
|
more_tag_keys = attribs[:tags].split('|')
|
112
252
|
attribs.delete(:tags)
|
113
253
|
|
114
|
-
## unify; replace
|
254
|
+
## unify; replace _ w/ space; remove leading n trailing whitespace
|
115
255
|
more_tag_keys = more_tag_keys.map do |key|
|
116
256
|
key = key.gsub( '_', ' ' )
|
117
257
|
key = key.strip
|
@@ -128,17 +268,61 @@ private
|
|
128
268
|
value_country_key = value[8..-1] ## cut off country: prefix
|
129
269
|
value_country = Country.find_by_key!( value_country_key )
|
130
270
|
attribs[ :country_id ] = value_country.id
|
271
|
+
elsif value =~ /^region:/ ## region:
|
272
|
+
value_region_key = value[7..-1] ## cut off region: prefix
|
273
|
+
value_region = Region.find_by_key_and_country_id!( value_region_key, attribs[:country_id] )
|
274
|
+
attribs[ :region_id ] = value_region.id
|
275
|
+
elsif value =~ /^[A-Z]{1,2}$/ ## assume region code e.g. TX or N
|
276
|
+
value_region = Region.find_by_key_and_country_id!( value.downcase, attribs[:country_id] )
|
277
|
+
attribs[ :region_id ] = value_region.id
|
131
278
|
elsif value =~ /^city:/ ## city:
|
132
279
|
value_city_key = value[5..-1] ## cut off city: prefix
|
133
|
-
value_city = City.find_by_key
|
134
|
-
|
280
|
+
value_city = City.find_by_key( value_city_key )
|
281
|
+
if value_city.present?
|
282
|
+
attribs[ :city_id ] = value_city.id
|
283
|
+
else
|
284
|
+
## todo/fix: add strict mode flag - fail w/ exit 1 in strict mode
|
285
|
+
logger.warn "city with key #{value_city_key} missing"
|
286
|
+
end
|
287
|
+
elsif value =~ /^by:/ ## by: -brewed by/brewery
|
288
|
+
value_brewery_key = value[3..-1] ## cut off by: prefix
|
289
|
+
value_brewery = Brewery.find_by_key!( value_brewery_key )
|
290
|
+
attribs[ :brewery_id ] = value_brewery.id
|
291
|
+
|
292
|
+
# for easy queries cache city and region ids
|
293
|
+
|
294
|
+
# 1) check if brewery has city - if yes, use it for beer too
|
295
|
+
if value_brewery.city.present?
|
296
|
+
attribs[ :city_id ] = value_brewery.city.id
|
297
|
+
end
|
298
|
+
|
299
|
+
# 2) check if brewery has city w/ region if yes, use it for beer to
|
300
|
+
# if not check for region for brewery
|
301
|
+
if value_brewery.city.present? && value_brewery.city.region.present?
|
302
|
+
attribs[ :region_id ] = value_brewery.city.region.id
|
303
|
+
elsif value_brewery.region.present?
|
304
|
+
attribs[ :region_id ] = value_brewery.region.id
|
305
|
+
end
|
306
|
+
|
307
|
+
elsif value =~ /^<?\s*(\d+(?:\.\d+)?)\s*%$/ ## abv (alcohol by volumee)
|
308
|
+
## nb: allow leading < e.g. <0.5%
|
309
|
+
value_abv_str = $1.dup # convert to decimal? how? use float?
|
310
|
+
attribs[ :abv ] = value_abv_str
|
311
|
+
elsif value =~ /^(\d+(?:\.\d+)?)°$/ ## plato (stammwuerze/gravity?) e.g. 11.2°
|
312
|
+
## nb: no whitespace allowed between ° and number e.g. 11.2°
|
313
|
+
value_plato_str = $1.dup # convert to decimal? how? use float?
|
314
|
+
attribs[ :plato ] = value_plato_str
|
315
|
+
elsif value =~ /^(\d+(?:\.\d+)?)\s*kcal(?:\/100ml)?$/ ## kcal
|
316
|
+
## nb: allow 44.4 kcal/100ml or 44.4 kcal or 44.4kcal
|
317
|
+
value_kcal_str = $1.dup # convert to decimal? how? use float?
|
318
|
+
attribs[ :kcal ] = value_kcal_str
|
135
319
|
elsif (values.size==(index+1)) && value =~ /^[a-z0-9\|_ ]+$/ # tags must be last entry
|
136
320
|
|
137
321
|
logger.debug " found tags: >>#{value}<<"
|
138
322
|
|
139
323
|
tag_keys = value.split('|')
|
140
324
|
|
141
|
-
## unify; replace
|
325
|
+
## unify; replace _ w/ space; remove leading n trailing whitespace
|
142
326
|
tag_keys = tag_keys.map do |key|
|
143
327
|
key = key.gsub( '_', ' ' )
|
144
328
|
key = key.strip
|
@@ -166,7 +350,6 @@ private
|
|
166
350
|
|
167
351
|
rec.update_attributes!( attribs )
|
168
352
|
|
169
|
-
=begin
|
170
353
|
##################
|
171
354
|
## add taggings
|
172
355
|
|
@@ -186,8 +369,7 @@ private
|
|
186
369
|
rec.tags << tag
|
187
370
|
end
|
188
371
|
end
|
189
|
-
|
190
|
-
|
372
|
+
|
191
373
|
end # each_line
|
192
374
|
|
193
375
|
end # method load_beers_worker
|
data/lib/beerdb/schema.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
|
2
3
|
module BeerDb
|
3
4
|
|
@@ -7,9 +8,10 @@ class CreateDb < ActiveRecord::Migration
|
|
7
8
|
def up
|
8
9
|
|
9
10
|
create_table :beers do |t|
|
10
|
-
t.string :title, :null => false
|
11
11
|
t.string :key, :null => false # import/export key
|
12
|
+
t.string :title, :null => false
|
12
13
|
t.string :synonyms # comma separated list of synonyms
|
14
|
+
|
13
15
|
t.boolean :bottle, :null => false, :default => false # Flaschenbier
|
14
16
|
t.boolean :draft, :null => false, :default => false # Fassbier
|
15
17
|
## todo: check seasonal is it proper english?
|
@@ -17,19 +19,52 @@ create_table :beers do |t|
|
|
17
19
|
## todo: add microbrew/brewpub flag?
|
18
20
|
#### t.boolean :brewpub, :null => false, :default => false
|
19
21
|
|
22
|
+
## add t.boolean :lite flag ??
|
23
|
+
t.decimal :kcal # kcal/100ml e.g. 45.0 kcal/100ml
|
24
|
+
|
25
|
+
## check: why decimal and not float?
|
26
|
+
t.decimal :abv # Alcohol by volume (abbreviated as ABV, abv, or alc/vol) e.g. 4.9 %
|
27
|
+
t.decimal :plato # stammwuerze / gravity in plato scale (e.g. °P) e.g. 12.6° - todo: use a different field name e.g. just p or gravity?
|
28
|
+
t.integer :color # beer color in Standard Reference Method (SRM)
|
29
|
+
|
30
|
+
# see en.wikipedia.org/wiki/Plato_scale#Colour
|
31
|
+
|
32
|
+
# SRM/Lovibond | Example | Beer color | EBC
|
33
|
+
# ---------------------------------------------------------------
|
34
|
+
# 2 | Pale lager, Witbier, Pilsener, Berliner Weisse | #F8F753 | 4
|
35
|
+
# 3 | Maibock, Blonde Ale | #F6F513 | 6
|
36
|
+
# 4 | Weissbier | #ECE61A | 8
|
37
|
+
# 6 | American Pale Ale, India Pale Ale | #D5BC26 | 12
|
38
|
+
# 8 | Weissbier, Saison | #BF923B | 16
|
39
|
+
# 10 | English Bitter, ESB | #BF813A | 20
|
40
|
+
# 13 | Biere de Garde, Double IPA | #BC6733 | 26
|
41
|
+
# 17 | Dark lager, Vienna lager, Marzen, Amber Ale | #8D4C32 | 33
|
42
|
+
# 20 | Brown Ale, Bock, Dunkel, Dunkelweizen | #5D341A | 39
|
43
|
+
# 24 | Irish Dry Stout, Doppelbock, Porter | #261716 | 47
|
44
|
+
# 29 | Stout | #0F0B0A | 57
|
45
|
+
# 35 | Foreign Stout, Baltic Porter | #080707 | 69
|
46
|
+
# 40+ | Imperial Stout | #030403 | 79
|
47
|
+
|
48
|
+
t.references :brewery # optional (for now)
|
49
|
+
|
20
50
|
t.references :country, :null => false
|
21
|
-
t.references :
|
22
|
-
|
51
|
+
t.references :region # optional
|
52
|
+
t.references :city # optional
|
53
|
+
|
23
54
|
t.timestamps
|
24
55
|
end
|
25
56
|
|
26
57
|
|
27
58
|
create_table :breweries do |t|
|
28
|
-
t.string :title
|
29
59
|
t.string :key, :null => false # import/export key
|
60
|
+
t.string :title, :null => false
|
30
61
|
t.string :synonyms # comma separated list of synonyms
|
62
|
+
t.string :address
|
63
|
+
t.integer :founded # year founded/established
|
64
|
+
|
31
65
|
t.references :country, :null => false
|
32
|
-
t.references :
|
66
|
+
t.references :region # optional
|
67
|
+
t.references :city # optional
|
33
68
|
|
34
69
|
t.timestamps
|
35
70
|
end
|
data/lib/beerdb/version.rb
CHANGED
data/lib/beerdb.rb
CHANGED
@@ -27,7 +27,9 @@ require 'beerdb/version'
|
|
27
27
|
|
28
28
|
require 'beerdb/models/forward'
|
29
29
|
require 'beerdb/models/country'
|
30
|
+
require 'beerdb/models/region'
|
30
31
|
require 'beerdb/models/city'
|
32
|
+
require 'beerdb/models/tag'
|
31
33
|
require 'beerdb/models/beer'
|
32
34
|
require 'beerdb/models/brewery'
|
33
35
|
require 'beerdb/schema'
|
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.
|
4
|
+
version: 0.2.0
|
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-03-
|
12
|
+
date: 2013-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &83368970 !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: *83368970
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: worlddb
|
27
|
-
requirement: &
|
27
|
+
requirement: &83368740 !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: *83368740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: commander
|
38
|
-
requirement: &
|
38
|
+
requirement: &83368520 !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: *83368520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &83368300 !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: *83368300
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: hoe
|
60
|
-
requirement: &
|
60
|
+
requirement: &84239690 !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: *84239690
|
69
69
|
description: beerdb - beer.db command line tool
|
70
70
|
email: tobedone@googlegroups.com
|
71
71
|
executables:
|
@@ -82,12 +82,15 @@ files:
|
|
82
82
|
- lib/beerdb.rb
|
83
83
|
- lib/beerdb/cli/main.rb
|
84
84
|
- lib/beerdb/cli/opts.rb
|
85
|
+
- lib/beerdb/console.rb
|
85
86
|
- lib/beerdb/deleter.rb
|
86
87
|
- lib/beerdb/models/beer.rb
|
87
88
|
- lib/beerdb/models/brewery.rb
|
88
89
|
- lib/beerdb/models/city.rb
|
89
90
|
- lib/beerdb/models/country.rb
|
90
91
|
- lib/beerdb/models/forward.rb
|
92
|
+
- lib/beerdb/models/region.rb
|
93
|
+
- lib/beerdb/models/tag.rb
|
91
94
|
- lib/beerdb/reader.rb
|
92
95
|
- lib/beerdb/schema.rb
|
93
96
|
- lib/beerdb/stats.rb
|