beerdb 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -9,6 +9,7 @@ lib/beerdb/cli/opts.rb
9
9
  lib/beerdb/console.rb
10
10
  lib/beerdb/deleter.rb
11
11
  lib/beerdb/models/beer.rb
12
+ lib/beerdb/models/brand.rb
12
13
  lib/beerdb/models/brewery.rb
13
14
  lib/beerdb/models/city.rb
14
15
  lib/beerdb/models/country.rb
data/bin/beerdb CHANGED
File without changes
@@ -10,6 +10,7 @@ module BeerDb
10
10
  # for now delete all tables
11
11
 
12
12
  Beer.delete_all
13
+ Brand.delete_all
13
14
  Brewery.delete_all
14
15
  end
15
16
 
@@ -8,6 +8,7 @@ class Beer < ActiveRecord::Base
8
8
  belongs_to :region, :class_name => 'WorldDb::Models::Region', :foreign_key => 'region_id'
9
9
  belongs_to :city, :class_name => 'WorldDb::Models::City', :foreign_key => 'city_id'
10
10
 
11
+ belongs_to :brand, :class_name => 'BeerDb::Models::Brewery', :foreign_key => 'brand_id'
11
12
  belongs_to :brewery, :class_name => 'BeerDb::Models::Brewery', :foreign_key => 'brewery_id'
12
13
 
13
14
  has_many :taggings, :as => :taggable, :class_name => 'WorldDb::Models::Tagging'
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ module BeerDb::Models
4
+
5
+ class Brand < ActiveRecord::Base
6
+
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'
9
+ belongs_to :city, :class_name => 'WorldDb::Models::City', :foreign_key => 'city_id'
10
+
11
+ belongs_to :brewery, :class_name => 'BeerDb::Models::Brewery', :foreign_key => 'brewery_id'
12
+
13
+ has_many :beers, :class_name => 'BeerDb::Models::Beer', :foreign_key => 'brand_id'
14
+
15
+ validates :key, :format => { :with => /^[a-z][a-z0-9]+$/, :message => 'expected two or more lowercase letters a-z or 0-9 digits' }
16
+
17
+ end # class Brand
18
+
19
+ end # module BeerDb::Models
@@ -11,6 +11,7 @@ class Brewery < ActiveRecord::Base
11
11
  belongs_to :city, :class_name => 'WorldDb::Models::City', :foreign_key => 'city_id'
12
12
 
13
13
  has_many :beers, :class_name => 'BeerDb::Models::Beer', :foreign_key => 'brewery_id'
14
+ has_many :brands, :class_name => 'BeerDb::Models::Brand', :foreign_key => 'brand_id'
14
15
 
15
16
  has_many :taggings, :as => :taggable, :class_name => 'WorldDb::Models::Tagging'
16
17
  has_many :tags, :through => :taggings, :class_name => 'WorldDb::Models::Tag'
@@ -83,6 +84,8 @@ class Brewery < ActiveRecord::Base
83
84
  end
84
85
  elsif value =~ /^[0-9]{4}$/ # founded/established year e.g. 1776
85
86
  new_attributes[ :since ] = value.to_i
87
+ elsif value =~ /^(?:([0-9][0-9_]*[0-9]|[0-9])\s?hl)$/ # e.g. 20_0000 hl or 50hl etc.
88
+ new_attributes[ :prod ] << $1.gsub(/_/, '').to_i
86
89
  elsif value =~ /^www\.|\.com$/ # check for url/internet address e.g. www.ottakringer.at
87
90
  # fix: support more url format (e.g. w/o www. - look for .com .country code etc.)
88
91
  new_attributes[ :web ] = value
@@ -16,6 +16,7 @@ module BeerDb::Models
16
16
  Prop = WorldDb::Models::Prop
17
17
 
18
18
  class Beer < ActiveRecord::Base ; end
19
+ class Brand < ActiveRecord::Base ; end
19
20
  class Brewery < ActiveRecord::Base ; end
20
21
 
21
22
  end
@@ -24,6 +25,7 @@ end
24
25
  module WorldDb::Models
25
26
 
26
27
  Beer = BeerDb::Models::Beer
28
+ Brand = BeerDb::Models::Brand
27
29
  Brewery = BeerDb::Models::Brewery
28
30
 
29
31
  end
data/lib/beerdb/reader.rb CHANGED
@@ -68,15 +68,65 @@ 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 =~ /\.hl$/ # e.g. breweries.hl # NB: must end w/ .hl
72
+ load_brewery_prod( name )
73
+ elsif name =~ /\/([a-z]{2})\.wikipedia/ # e.g. de.wikipedia
74
+ # auto-add required lang e.g. de or en etc.
75
+ load_brewery_wiki( $1, name )
76
+ elsif name =~ /\/([a-z]{2})\/breweries_([a-z]{1,2})(?:_|$)/ # NB: region key must end name or be followed by underscore (_)
77
+ ## auto-add required country code (from folder structure) plus region
78
+ load_breweries_for_country_n_region( $1, $2, name )
71
79
  elsif name =~ /\/([a-z]{2})\/breweries/
72
80
  ## auto-add required country code (from folder structure)
73
- load_breweries( $1, name )
81
+ load_breweries_for_country( $1, name )
74
82
  else
75
83
  logger.error "unknown beer.db fixture type >#{name}<"
76
84
  # todo/fix: exit w/ error
77
85
  end
78
86
  end
79
-
87
+
88
+ def load_brewery_wiki( lang_key, name )
89
+ path = "#{include_path}/#{name}.yml"
90
+
91
+ logger.info "parsing data '#{name}' (#{path})..."
92
+
93
+ reader = HashReader.new( path )
94
+
95
+ reader.each do |key, value|
96
+ brewery = Brewery.find_by_key!( key )
97
+
98
+ wiki = "#{lang_key}.wikipedia.org/wiki/#{value.strip}"
99
+ logger.debug " adding #{key} => >#{wiki}<"
100
+ brewery.wiki = wiki
101
+ brewery.save!
102
+ end
103
+
104
+ Prop.create_from_fixture!( name, path )
105
+ end
106
+
107
+
108
+ def load_brewery_prod( name )
109
+ path = "#{include_path}/#{name}.yml"
110
+
111
+ logger.info "parsing data '#{name}' (#{path})..."
112
+
113
+ reader = HashReader.new( path )
114
+
115
+ reader.each do |key, value|
116
+ brewery = Brewery.find_by_key!( key )
117
+
118
+ if value =~ /(?:([0-9][0-9_]*[0-9]|[0-9])\s*hl)/ # e.g. 20_0000 hl or 50hl etc.
119
+ prod = $1.gsub(/_/, '').to_i
120
+ logger.debug " adding #{key} => >#{prod}<"
121
+ brewery.prod = prod
122
+ brewery.save!
123
+ else
124
+ logger.warn " unknown type for brewery prod value >#{value}<; regex pattern match failed"
125
+ end
126
+ end
127
+
128
+ Prop.create_from_fixture!( name, path )
129
+ end
80
130
 
81
131
  def load_beers( country_key, name, more_values={} )
82
132
  country = Country.find_by_key!( country_key )
@@ -98,12 +148,32 @@ class Reader
98
148
  end
99
149
 
100
150
 
101
- def load_breweries( country_key, name, more_values={} )
151
+ def load_breweries_for_country_n_region( country_key, region_key, name, more_values={} )
152
+ country = Country.find_by_key!( country_key )
153
+ logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
154
+
155
+ # NB: region lookup requires country id (region key only unique for country)
156
+ region = Region.find_by_key_and_country_id!( region_key, country.id )
157
+ logger.debug "Region #{region.key} >#{region.title}<"
158
+
159
+ more_values[ :country_id ] = country.id
160
+ more_values[ :region_id ] = region.id
161
+
162
+ load_breweries_worker( name, more_values )
163
+ end
164
+
165
+
166
+ def load_breweries_for_country( country_key, name, more_values={} )
102
167
  country = Country.find_by_key!( country_key )
103
168
  logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
104
169
 
105
170
  more_values[ :country_id ] = country.id
106
171
 
172
+ load_breweries_worker( name, more_values )
173
+ end
174
+
175
+
176
+ def load_breweries_worker( name, more_values={} )
107
177
  path = "#{include_path}/#{name}.txt"
108
178
 
109
179
  logger.info "parsing data '#{name}' (#{path})..."
data/lib/beerdb/schema.rb CHANGED
@@ -55,6 +55,15 @@ create_table :beers do |t|
55
55
  # 40+ | Imperial Stout | #030403 | 79
56
56
 
57
57
  t.references :brewery # optional (for now)
58
+ t.references :brand # optional (for now)
59
+
60
+
61
+ ## todo: add categories e.g. (A/B/C, 1/2/3, main/major/minor ??)
62
+ # - A-grade /1st class/ tier1 / main beer brand/bestseller/flagship ?
63
+ # - B-grade /2nd class/ tier2 / regular, major, - todo: find better names?
64
+ # - C-grade /3nd class/ tier3/ / speciality, minor ?
65
+
66
+ t.integer :grade # 1/2/3 (A/B/C)
58
67
 
59
68
  t.references :country, :null => false
60
69
  t.references :region # optional
@@ -64,6 +73,32 @@ create_table :beers do |t|
64
73
  end
65
74
 
66
75
 
76
+ create_table :brands do |t| # beer families (sharing same name e.g. brand)
77
+ t.string :key, :null => false # import/export key
78
+ t.string :title, :null => false
79
+ t.string :synonyms # comma separated list of synonyms
80
+ t.string :web # optional web page (e.g. www.ottakringer.at)
81
+ t.string :wiki # optional wiki(pedia page)
82
+ t.integer :since
83
+
84
+ ## scope of brand (global/intern'l/national/regional/local) ??
85
+ t.boolean :global, :null => false, :default => false
86
+ t.boolean :internl, :null => false, :default => false
87
+ t.boolean :national, :null => false, :default => false
88
+ t.boolean :regional, :null => false, :default => false
89
+ t.boolean :local, :null => false, :default => false
90
+
91
+ t.integer :grade # 1/2/3/4/5 (global/intern'l/national/regional/local)
92
+
93
+ t.references :brewery # optional (for now)
94
+
95
+ t.references :country, :null => false
96
+ t.references :region # optional
97
+ t.references :city # optional
98
+
99
+ t.timestamps
100
+ end
101
+
67
102
  create_table :breweries do |t|
68
103
  t.string :key, :null => false # import/export key
69
104
  t.string :title, :null => false
@@ -76,9 +111,40 @@ create_table :breweries do |t|
76
111
 
77
112
  ## todo: add optional parent brewery (owned_by)
78
113
 
79
- t.integer :prod # (estimated) annual production in hl (1hl=100l) e.g. megabrewery 2_000_000, microbrewery 1_000 hl; brewbup 500 hl etc.
114
+ t.integer :prod # (estimated) annual production/capacity in hl (1hl=100l) e.g. megabrewery 2_000_000, microbrewery 1_000 hl; brewbup 500 hl etc.
115
+
116
+ # grade - classified using annual production (capacity) in hl
117
+ # < 1_000 hl => 11
118
+ # < 3_000 hl => 10
119
+ # < 5_000 hl => 9
120
+ # < 10_000 hl => 8
121
+ # < 50_000 hl => 7
122
+ # < 100_000 hl => 6
123
+ # < 200_000 hl => 5
124
+ # < 500_000 hl => 4
125
+ # < 1_000_000 hl => 3
126
+ # < 2_000_000 hl => 2
127
+ # > 2_000_000 hl => 1
128
+
129
+ t.integer :grade # 1/2/3/4/5/6/7/8/9/10/11
130
+
80
131
 
81
132
  t.string :web # optional web page (e.g. www.ottakringer.at)
133
+ t.string :wiki # optional wiki(pedia page)
134
+
135
+ t.boolean :indie # independent brewery (flag)
136
+
137
+ # for convenience (easy queries) use flags for top beer multinationals (-- later use just tags? more flexible)
138
+ t.boolean :abinbev # owned by AB InBev / Anheuser-Busch InBev (and Grupo Modelo)
139
+ t.boolean :sabmiller # owned by SAB Miller (in US cooperates w/ Molson Coors using MillerCoors venture)
140
+ t.boolean :heineken # owned by Heineken
141
+ t.boolean :carlsberg # owned by Carlsberg
142
+ t.boolean :molsoncoors # owned by Molson Coors
143
+ t.boolean :diageo # owned by Diageo (e.g. Guiness, Kilkenny,...)
144
+
145
+
146
+ # todo: add t.references :parent # for parent brewery
147
+ # (or better use has many parents w/ percentage of ownership; might not be 100%)
82
148
 
83
149
  t.references :country, :null => false
84
150
  t.references :region # optional
data/lib/beerdb/stats.rb CHANGED
@@ -8,6 +8,7 @@ module BeerDb
8
8
  def tables
9
9
  puts "Stats:"
10
10
  puts " #{'%5d' % Beer.count} beers"
11
+ puts " #{'%5d' % Brand.count} brands"
11
12
  puts " #{'%5d' % Brewery.count} breweries"
12
13
  end
13
14
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module BeerDb
3
- VERSION = '0.5.2'
3
+ VERSION = '0.6.0'
4
4
  end
data/lib/beerdb.rb CHANGED
@@ -31,6 +31,7 @@ require 'beerdb/models/region'
31
31
  require 'beerdb/models/city'
32
32
  require 'beerdb/models/tag'
33
33
  require 'beerdb/models/beer'
34
+ require 'beerdb/models/brand'
34
35
  require 'beerdb/models/brewery'
35
36
  require 'beerdb/schema'
36
37
  require 'beerdb/reader'
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.5.2
4
+ version: 0.6.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-04-23 00:00:00.000000000Z
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &20592228 !ruby/object:Gem::Requirement
16
+ requirement: &73799560 !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: *20592228
24
+ version_requirements: *73799560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: worlddb
27
- requirement: &20591964 !ruby/object:Gem::Requirement
27
+ requirement: &73799340 !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: *20591964
35
+ version_requirements: *73799340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: commander
38
- requirement: &20591700 !ruby/object:Gem::Requirement
38
+ requirement: &73799120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,38 +43,36 @@ dependencies:
43
43
  version: 4.1.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20591700
46
+ version_requirements: *73799120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &20591436 !ruby/object:Gem::Requirement
49
+ requirement: &73798900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '4.0'
54
+ version: '3.10'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20591436
57
+ version_requirements: *73798900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &20591172 !ruby/object:Gem::Requirement
60
+ requirement: &73798680 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
64
64
  - !ruby/object:Gem::Version
65
- version: '3.6'
65
+ version: '3.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *20591172
68
+ version_requirements: *73798680
69
69
  description: beerdb - beer.db command line tool
70
70
  email: beerdb@googlegroups.com
71
71
  executables:
72
72
  - beerdb
73
73
  extensions: []
74
74
  extra_rdoc_files:
75
- - History.md
76
75
  - Manifest.txt
77
- - README.md
78
76
  files:
79
77
  - History.md
80
78
  - Manifest.txt
@@ -87,6 +85,7 @@ files:
87
85
  - lib/beerdb/console.rb
88
86
  - lib/beerdb/deleter.rb
89
87
  - lib/beerdb/models/beer.rb
88
+ - lib/beerdb/models/brand.rb
90
89
  - lib/beerdb/models/brewery.rb
91
90
  - lib/beerdb/models/city.rb
92
91
  - lib/beerdb/models/country.rb
@@ -127,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
126
  version: '0'
128
127
  requirements: []
129
128
  rubyforge_project: beerdb
130
- rubygems_version: 1.7.2
129
+ rubygems_version: 1.8.17
131
130
  signing_key:
132
131
  specification_version: 3
133
132
  summary: beerdb - beer.db command line tool