winedb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,13 +3,21 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/winedb.rb
6
- lib/winedb/models/city.rb
7
- lib/winedb/models/country.rb
6
+ lib/winedb/models/family.rb
8
7
  lib/winedb/models/forward.rb
9
- lib/winedb/models/region.rb
8
+ lib/winedb/models/grape.rb
9
+ lib/winedb/models/person.rb
10
+ lib/winedb/models/shop.rb
10
11
  lib/winedb/models/tag.rb
12
+ lib/winedb/models/tavern.rb
13
+ lib/winedb/models/variety.rb
14
+ lib/winedb/models/vineyard.rb
15
+ lib/winedb/models/vintage.rb
11
16
  lib/winedb/models/wine.rb
12
17
  lib/winedb/models/winery.rb
18
+ lib/winedb/models/worlddb/city.rb
19
+ lib/winedb/models/worlddb/country.rb
20
+ lib/winedb/models/worlddb/region.rb
13
21
  lib/winedb/reader.rb
14
22
  lib/winedb/schema.rb
15
23
  lib/winedb/version.rb
@@ -15,13 +15,25 @@ require 'winedb/version' # let it always go first
15
15
  require 'winedb/schema'
16
16
 
17
17
  require 'winedb/models/forward'
18
- require 'winedb/models/city'
19
- require 'winedb/models/country'
20
- require 'winedb/models/region'
18
+
19
+ require 'winedb/models/worlddb/country'
20
+ require 'winedb/models/worlddb/region'
21
+ require 'winedb/models/worlddb/city'
22
+
21
23
  require 'winedb/models/tag'
24
+
25
+ require 'winedb/models/family'
26
+ require 'winedb/models/grape'
27
+ require 'winedb/models/person'
28
+ require 'winedb/models/shop'
29
+ require 'winedb/models/tavern'
30
+ require 'winedb/models/variety'
31
+ require 'winedb/models/vineyard'
32
+ require 'winedb/models/vintage'
22
33
  require 'winedb/models/wine'
23
34
  require 'winedb/models/winery'
24
35
 
36
+
25
37
  require 'winedb/reader'
26
38
 
27
39
  module WineDb
@@ -57,6 +69,34 @@ module WineDb
57
69
  read_setup( 'setups/all', include_path, opts )
58
70
  end # method read_all
59
71
 
72
+ def self.delete!
73
+ ## fix/todo: move into deleter class (see worlddb,sportdb etc.)
74
+ Model::Grape.delete_all
75
+ Model::Family.delete_all
76
+ Model::Variety.delete_all
77
+ Model::Vineyard.delete_all
78
+ Model::Person.delete_all
79
+ Model::Shop.delete_all
80
+ Model::Tavern.delete_all
81
+ Model::Vintage.delete_all
82
+ Model::Wine.delete_all
83
+ Model::Winery.delete_all
84
+ end
85
+
86
+ def self.tables
87
+ ## fix/todo: move into stats class (see worlddb,sportdb etc.)
88
+ puts " #{Model::Grape.count} grapes"
89
+ puts " #{Model::Family.count} (wine) families"
90
+ puts " #{Model::Variety.count} (wine) varieties"
91
+ puts " #{Model::Vineyard.count} vineyards"
92
+ puts " #{Model::Person.count} persons (winemakers)"
93
+ puts " #{Model::Shop.count} shops (vinothek/enotecia)"
94
+ puts " #{Model::Tavern.count} taverns (heurige)"
95
+ puts " #{Model::Vintage.count} vintages"
96
+ puts " #{Model::Wine.count} wines"
97
+ puts " #{Model::Winery.count} wineries"
98
+ end
99
+
60
100
 
61
101
  end # module WineDb
62
102
 
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ ###################
7
+ # (Wine)-Family
8
+ #
9
+ # e.g. - Red Wine
10
+ # - White Wine
11
+ # - Rose Wine
12
+ # - Desert (Sweet)
13
+ # - Sparkling (Champagne)
14
+ # - Fortified (Brandy,Port)
15
+ # - Other
16
+
17
+ class Family < ActiveRecord::Base
18
+
19
+ self.table_name = 'families'
20
+ ## to be done
21
+
22
+ end # class Family
23
+
24
+
25
+ end # module Model
26
+ end # module WineDb
@@ -19,6 +19,14 @@ module WineDb
19
19
 
20
20
  class Wine < ActiveRecord::Base ; end
21
21
  class Winery < ActiveRecord::Base ; end
22
+ class Grape < ActiveRecord::Base ; end
23
+ class Family < ActiveRecord::Base ; end
24
+ class Variety < ActiveRecord::Base ; end
25
+ class Vineyard < ActiveRecord::Base ; end
26
+ class Person < ActiveRecord::Base ; end
27
+ class Shop < ActiveRecord::Base ; end
28
+ class Tavern < ActiveRecord::Base ; end
29
+ class Vintage < ActiveRecord::Base ; end
22
30
 
23
31
  end # module Model
24
32
 
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ class Grape < ActiveRecord::Base
7
+
8
+ ## to be done
9
+
10
+ end # class Grape
11
+
12
+
13
+ end # module Model
14
+ end # module WineDb
@@ -0,0 +1,17 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ ###
7
+ # Winemaker
8
+
9
+ class Person < ActiveRecord::Base
10
+
11
+ self.table_name = 'persons'
12
+ ## to be done
13
+
14
+ end # class Person
15
+
16
+ end # module Model
17
+ end # module WineDb
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ class Shop < ActiveRecord::Base
7
+
8
+ has_many :taggings, :as => :taggable, class_name: 'WorldDb::Model::Tagging'
9
+ has_many :tags, :through => :taggings, class_name: 'WorldDb::Model::Tag'
10
+
11
+ validates :key, :format => { :with => /^[a-z][a-z0-9]+$/, :message => 'expected two or more lowercase letters a-z or 0-9 digits' }
12
+
13
+ ## to be done
14
+
15
+ end # class Shop
16
+
17
+
18
+ end # module Model
19
+ end # module WineDb
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ class Tavern < ActiveRecord::Base
7
+
8
+ belongs_to :winery, class_name: 'WineDb::Model::Winery', foreign_key: 'winery_id'
9
+
10
+ has_many :taggings, :as => :taggable, class_name: 'WorldDb::Model::Tagging'
11
+ has_many :tags, :through => :taggings, class_name: 'WorldDb::Model::Tag'
12
+
13
+ validates :key, :format => { :with => /^[a-z][a-z0-9]+$/, :message => 'expected two or more lowercase letters a-z or 0-9 digits' }
14
+
15
+ ## to be done
16
+
17
+ end # class Tavern
18
+
19
+
20
+ end # module Model
21
+ end # module WineDb
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ class Variety < ActiveRecord::Base
7
+
8
+ self.table_name = 'varieties'
9
+ ## to be done
10
+
11
+ end # class Variety
12
+
13
+
14
+ end # module Model
15
+ end # module WineDb
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ class Vineyard < ActiveRecord::Base
7
+
8
+ has_many :wines, class_name: 'WineDb::Model::Wine', foreign_key: 'vineyard_id'
9
+
10
+ ## to be done
11
+
12
+ end # class Vineyard
13
+
14
+ end # module Model
15
+ end # module WineDb
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ module WineDb
4
+ module Model
5
+
6
+ class Vintage < ActiveRecord::Base
7
+
8
+ ## to be done
9
+
10
+ end # class Vintage
11
+
12
+
13
+ end # module Model
14
+ end # module WineDb
@@ -11,9 +11,10 @@ class Wine < ActiveRecord::Base
11
11
  # self.create_or_update_from_values
12
12
  extend TextUtils::ValueHelper # e.g. self.is_year?, self.is_region?, self.is_address?, is_taglist? etc.
13
13
 
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'
16
- belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
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'
16
+ belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
17
+ belongs_to :vineyard, class_name: 'WineDb::Model::Vineyard', foreign_key: 'vinyard_id'
17
18
 
18
19
  belongs_to :winery, :class_name => 'WineDb::Model::Winery', foreign_key: 'winery_id'
19
20
 
@@ -66,10 +67,11 @@ class Wine < ActiveRecord::Base
66
67
  elsif match_website( value ) do |website| # check for url/internet address e.g. www.ottakringer.at
67
68
  attribs[ :web ] = website
68
69
  end
69
- elsif match_abv( value ) do |num| # abv (alcohol by volume)
70
- # nb: also allows leading < e.g. <0.5%
71
- attribs[ :abv ] = num
72
- end
70
+ # -- moved to vintage (that is, abv depends on year)
71
+ # elsif match_abv( value ) do |num| # abv (alcohol by volume)
72
+ # # nb: also allows leading < e.g. <0.5%
73
+ # attribs[ :abv ] = num
74
+ # end
73
75
  elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
74
76
  logger.debug " found tags: >>#{value}<<"
75
77
  value_tag_keys += find_tags( value )
@@ -18,6 +18,7 @@ class Winery < ActiveRecord::Base
18
18
  belongs_to :region, class_name: 'WorldDb::Model::Region', foreign_key: 'region_id'
19
19
  belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
20
20
 
21
+ has_one :tavern, class_name: 'WineDb::Model::Tavern', foreign_key: 'tavern_id'
21
22
  has_many :wines, class_name: 'WineDb::Model::Wine', foreign_key: 'wine_id'
22
23
 
23
24
  has_many :taggings, :as => :taggable, class_name: 'WorldDb::Model::Tagging'
@@ -0,0 +1,14 @@
1
+ module WorldDb
2
+ module Model
3
+
4
+ class City
5
+ has_many :wines, class_name: 'WineDb::Model::Wine', foreign_key: 'city_id'
6
+ has_many :wineries, class_name: 'WineDb::Model::Winery', foreign_key: 'city_id'
7
+ has_many :taverns, class_name: 'WineDb::Model::Tavern', foreign_key: 'city_id'
8
+ has_many :shops, class_name: 'WineDb::Model::Shop', foreign_key: 'city_id'
9
+ has_many :vineyards, class_name: 'WineDb::Model::Vineyard', foreign_key: 'city_id'
10
+ end # class Country
11
+
12
+
13
+ end # module Model
14
+ end # module WorldDb
@@ -5,6 +5,8 @@ module WorldDb
5
5
  class Country
6
6
  has_many :wines, class_name: 'WineDb::Model::Wine', foreign_key: 'country_id'
7
7
  has_many :wineries, class_name: 'WineDb::Model::Winery', foreign_key: 'country_id'
8
+ has_many :taverns, class_name: 'WineDb::Model::Tavern', foreign_key: 'country_id'
9
+ has_many :shops, class_name: 'WineDb::Model::Shop', foreign_key: 'country_id'
8
10
  end # class Country
9
11
 
10
12
 
@@ -0,0 +1,12 @@
1
+ module WorldDb
2
+ module Model
3
+
4
+ class Region
5
+ has_many :wines, class_name: 'WineDb::Model::Wine', foreign_key: 'region_id'
6
+ has_many :wineries, class_name: 'WineDb::Model::Winery', foreign_key: 'region_id'
7
+ has_many :taverns, class_name: 'WineDb::Model::Tavern', foreign_key: 'region_id'
8
+ has_many :shops, class_name: 'WineDb::Model::Shop', foreign_key: 'region_id'
9
+ end # class Region
10
+
11
+ end # module Model
12
+ end # module WorldDb
@@ -5,11 +5,12 @@ module WineDb
5
5
 
6
6
  module Matcher
7
7
 
8
- def match_wines_for_country( name, &blk )
9
- match_xxx_for_country( name, 'wines', &blk )
10
- end
8
+ def fix_match_xxx_for_country_n_region( name, xxx ) # xxx e.g. wine|wineries
9
+
10
+ ## todo/fix: move code into worlddb matcher!!!!
11
+ ## -- allow opt_folders after long regions
12
+ ## -- allow anything before -- for xxx
11
13
 
12
- def match_wines_for_country_n_region( name, &blk )
13
14
  ### fix allow prefixes for wines (move into core!!!) e.g.
14
15
  ##
15
16
  # at-austria!/1--n-niederoesterreich--eastern/wagram--wines
@@ -18,9 +19,53 @@ module Matcher
18
19
  ### strip subregion if present e.g.
19
20
  # /wagram--wines becomes /wines n
20
21
  # /wagram--wagram--wines becomes / wines etc.
21
- name_fixed = name.sub( /\/([a-z]+--)*wines$/, "/wines" )
22
22
 
23
- match_xxx_for_country_n_region( name_fixed, 'wines', &blk )
23
+ # auto-add required country n region code (from folder structure)
24
+
25
+ # note: allow /cities and /1--hokkaido--cities and /hokkaido--cities too
26
+ xxx_pattern = "(?:#{xxx}|[^\\/]+--#{xxx})" # note: double escape \\ required for backslash
27
+
28
+ ## allow optional folders -- TODO: add restriction ?? e.g. must be 4+ alphas ???
29
+ opt_folders_pattern = "(?:\/[^\/]+)*"
30
+ ## note: for now only (2) n (3) that is long region allow opt folders
31
+
32
+ if name =~ /(?:^|\/)([a-z]{2,3})-[^\/]+\/([a-z]{1,3})-[^\/]+\/#{xxx_pattern}/ || # (1)
33
+ name =~ /(?:^|\/)[0-9]+--([a-z]{2,3})-[^\/]+\/[0-9]+--([a-z]{1,3})-[^\/]+#{opt_folders_pattern}\/#{xxx_pattern}/ || # (2)
34
+ name =~ /(?:^|\/)([a-z]{2,3})-[^\/]+\/[0-9]+--([a-z]{1,3})-[^\/]+#{opt_folders_pattern}\/#{xxx_pattern}/ || # (3)
35
+ name =~ /(?:^|\/)[0-9]+--([a-z]{2,3})-[^\/]+\/([a-z]{1,3})-[^\/]+\/#{xxx_pattern}/ # (4)
36
+
37
+ #######
38
+ # nb: country must start name (^) or coming after / e.g. europe/at-austria/...
39
+ # (1)
40
+ # new style: e.g. /at-austria/w-wien/cities or
41
+ # ^at-austria!/w-wien/cities
42
+ # (2)
43
+ # new new style e.g. /1--at-austria--central/1--w-wien--eastern/cities
44
+ #
45
+ # (3)
46
+ # new new mixed style e.g. /at-austria/1--w-wien--eastern/cities
47
+ # "classic" country plus new new region
48
+ #
49
+ # (4)
50
+ # new new mixed style e.g. /1--at-austria--central/w-wien/cities
51
+ # new new country plus "classic" region
52
+
53
+ country_key = $1.dup
54
+ region_key = $2.dup
55
+ yield( country_key, region_key )
56
+ true # bingo - match found
57
+ else
58
+ false # no match found
59
+ end
60
+ end
61
+
62
+
63
+ def match_wines_for_country( name, &blk )
64
+ match_xxx_for_country( name, 'wines', &blk )
65
+ end
66
+
67
+ def match_wines_for_country_n_region( name, &blk )
68
+ fix_match_xxx_for_country_n_region( name, 'wines', &blk )
24
69
  end
25
70
 
26
71
  def match_wineries_for_country( name, &blk )
@@ -28,17 +73,20 @@ module Matcher
28
73
  end
29
74
 
30
75
  def match_wineries_for_country_n_region( name, &blk )
31
- ### fix allow prefixes for wineries (move into core!!!) e.g.
32
- ##
33
- # at-austria!/1--n-niederoesterreich--eastern/wagram--wineries
34
- # at-austria!/1--n-niederoesterreich--eastern/wagram--wagram--wineries
76
+ fix_match_xxx_for_country_n_region( name, 'wineries', &blk )
77
+ end
35
78
 
36
- ### strip subregion if present e.g.
37
- # /wagram--wineries becomes /wineries n
38
- # /wagram--wagram--wineries becomes / wineries etc.
39
- name_fixed = name.sub( /\/([a-z]+--)*wineries$/, "/wineries" )
79
+ ## for now vineyards, shops, taverns require country n region
80
+ def match_vineyards_for_country_n_region( name, &blk )
81
+ fix_match_xxx_for_country_n_region( name, 'vineyards', &blk )
82
+ end
83
+
84
+ def match_shops_for_country_n_region( name, &blk )
85
+ fix_match_xxx_for_country_n_region( name, 'shops', &blk )
86
+ end
40
87
 
41
- match_xxx_for_country_n_region( name_fixed, 'wineries', &blk )
88
+ def match_taverns_for_country_n_region( name, &blk )
89
+ fix_match_xxx_for_country_n_region( name, 'taverns', &blk )
42
90
  end
43
91
 
44
92
  end # module Matcher
@@ -7,27 +7,35 @@ class CreateDb < ActiveRecord::Migration
7
7
 
8
8
  def up
9
9
 
10
+ #######
11
+ # todo/fix: rename title to name
12
+
13
+
14
+
15
+ ###
16
+ # wines
17
+ #
18
+ # note: key is NOT unique; require winery key
19
+ # winery.key+wines.key => unique key e.g. antonbauer.gruenerveltiner
20
+
10
21
  create_table :wines do |t|
11
22
  t.string :key, null: false # import/export key
12
23
  t.string :title, null: false
13
24
  t.string :synonyms # comma separated list of synonyms
14
25
 
15
- t.string :web # optional url link (e.g. )
16
- t.integer :since # optional year (e.g. 1896)
17
-
18
- ## check: why decimal and not float?
19
- t.decimal :abv # Alcohol by volume (abbreviated as ABV, abv, or alc/vol) e.g. 4.9 %
20
-
21
26
  t.references :winery # optional (for now)
27
+ t.references :variety # optional (for now) -- todo/fix: make required!!! why not??? possible??
22
28
 
23
-
24
- t.string :txt # source ref
25
- t.boolean :txt_auto, null: false, default: false # inline? got auto-added?
26
-
29
+ t.string :web # optional url link (e.g. )
30
+ t.integer :since # optional year (e.g. 1896)
27
31
 
28
32
  t.references :country, null: false
29
33
  t.references :region # optional
30
34
  t.references :city # optional
35
+ t.references :vineyard # optional e.g. Spiegel, Gmoerk, Rosenberg, etc.
36
+
37
+ t.string :txt # source ref
38
+ t.boolean :txt_auto, null: false, default: false # inline? got auto-added?
31
39
 
32
40
  t.timestamps
33
41
  end
@@ -38,9 +46,7 @@ create_table :wineries do |t|
38
46
  t.string :title, null: false
39
47
  t.string :synonyms # comma separated list of synonyms
40
48
  t.string :address
41
- t.integer :since
42
- ## renamed to founded to since
43
- ## t.integer :founded # year founded/established - todo/fix: rename to since?
49
+ t.integer :since ## renamed founded to since
44
50
  t.integer :closed # optional; year winery closed
45
51
 
46
52
  t.integer :area # in ha e.g. 8 ha # Weingarten/rebflaeche
@@ -48,21 +54,174 @@ create_table :wineries do |t|
48
54
  # use stars in .txt e.g. # ***/**/*/- => 1/2/3/4
49
55
  t.integer :grade, null: false, default: 4
50
56
 
57
+ t.string :web # optional web page (e.g. www.ottakringer.at)
58
+ t.string :wikipedia # optional wiki(pedia page)
59
+
60
+
61
+ t.references :country, null: false
62
+ t.references :region # optional
63
+ t.references :city # optional
64
+
65
+ t.references :person # optional for now - winemaker/kellermeister e.g. Anton Bauer (1971) etc.
66
+ t.references :tavern # optional (heurige)
51
67
 
52
68
  t.string :txt # source ref
53
69
  t.boolean :txt_auto, null: false, default: false # inline? got auto-added?
54
70
 
71
+ t.timestamps
72
+ end
73
+
74
+ create_table :vintages do |t|
75
+ t.integer :year, null: false
76
+ t.references :wine, null: false
77
+
78
+ ## check: why decimal and not float?
79
+ t.decimal :abv # Alcohol by volume (abbreviated as ABV, abv, or alc/vol) e.g. 4.9 %
80
+
81
+ t.timestamps
82
+ end
83
+
84
+ create_table :grapes do |t|
85
+ t.string :key, null: false # import/export key
86
+ t.string :title, null: false
87
+ t.string :synonyms # comma separated list of synonyms
88
+
89
+ t.boolean :red, null: false, default: false
90
+ t.boolean :white, null: false, default: false
91
+
92
+ t.string :web # optional web page
93
+ t.string :wikipedia # optional wiki(pedia page)
94
+
95
+ t.timestamps
96
+ end
97
+
98
+ ####
99
+ # wine families
100
+ #
101
+ # todo/fix: allow subfamilies e.g. red wine => 1) red wine varietal, 2) red wine blended/cuvee etc.
102
+
103
+ create_table :families do |t| # wine family e.g. red wine/white wine/rose wine/sparkling(champagne,etc.)/desert(sweet)/fortified(port,etc.)/other etc.
104
+ t.string :key, null: false # import/export key
105
+ t.string :title, null: false
106
+ t.string :synonyms # comma separated list of synonyms
107
+
108
+ t.timestamps
109
+ end
110
+
111
+ ####
112
+ # wine variety
113
+ # e.g. varietal (Gr. Veltiner) or blend/cuvee (Red Wine Cuvee) etc.
114
+ create_table :varieties do |t|
115
+ t.string :key, null: false # import/export key
116
+ t.string :title, null: false
117
+ t.string :synonyms # comma separated list of synonyms
118
+ t.references :family, null: false
119
+
120
+ ## note: for now cuvee will NOT record blended varieties (maybe add later??)
121
+ t.boolean :cuvee, null: false, default: false # blended variety
122
+ t.boolean :varietal, null: false, default: false
123
+ t.references :grape # note: optional - only varietal has a main grape (+80%); cuvee/blended is a mix of grapes
124
+ t.timestamps
125
+ end
126
+
127
+ ##########################
128
+ # (Wine)Taverns/Heurige
129
+
130
+ create_table :taverns do |t|
131
+ t.string :key, null: false # import/export key
132
+ t.string :title, null: false
133
+ t.string :synonyms # comma separated list of synonyms
134
+ t.references :winery # for now optional -- todo/fix: make required!!!
135
+
136
+ t.string :address
137
+ t.integer :since
138
+
139
+ t.string :web # optional web page (e.g. www.urbaniheuriger.at)
140
+ t.string :wikipedia # optional wiki(pedia page)
141
+
142
+ t.references :country, null: false
143
+ t.references :region # optional
144
+ t.references :city # optional
145
+
146
+ t.string :txt # source ref
147
+ t.boolean :txt_auto, null: false, default: false # inline? got auto-added?
148
+
149
+ t.timestamps
150
+ end
151
+
152
+
153
+ #################################
154
+ # (Wine)Shops/Vinothek/Enoteca
155
+
156
+ create_table :shops do |t|
157
+ t.string :key, null: false # import/export key
158
+ t.string :title, null: false
159
+ t.string :synonyms # comma separated list of synonyms
160
+
161
+ t.string :address
162
+ t.integer :since
163
+
55
164
  t.string :web # optional web page (e.g. www.ottakringer.at)
56
165
  t.string :wikipedia # optional wiki(pedia page)
57
166
 
58
-
59
167
  t.references :country, null: false
60
168
  t.references :region # optional
61
169
  t.references :city # optional
62
-
170
+
171
+ t.string :txt # source ref
172
+ t.boolean :txt_auto, null: false, default: false # inline? got auto-added?
173
+
174
+ t.timestamps
175
+ end
176
+
177
+
178
+ ################
179
+ # vineyards
180
+ #
181
+ # e.g. Spiegel, Rosenberg, Gmoerk, etc.
182
+
183
+ create_table :vineyards do |t|
184
+ t.string :key, null: false # import/export key
185
+ t.string :title, null: false
186
+ t.string :synonyms # comma separated list of synonyms
187
+ t.references :city, null: false
188
+
189
+ t.integer :area # in ha e.g. 8 ha # Weingarten/rebflaeche
190
+
191
+ t.timestamps
192
+ end
193
+
194
+ #########################
195
+ # persons (wine makers)
196
+ # e.g. Anton Bauer (1971) etc.
197
+ #
198
+ # note: use persons table (not makers table) and use kind/typ for (wine)maker
199
+ #
200
+ # todo: move persons to friends.db project for (re)use;
201
+ # see player in football.db too ???
202
+ # and drivers in formula1.db too and
203
+ # and skiers in ski.db etc.
204
+
205
+ create_table :persons do |t| # use people ? instead of persons (person/persons makes it easier?)
206
+ t.string :key, null: false # import/export key
207
+ t.string :name, null: false
208
+ t.string :synonyms # comma separated list of synonyms
209
+
210
+ ## todo: add gender flag (male/female -man/lady how?)
211
+ t.date :born_at # optional date of birth (birthday)
212
+ ## todo: add country of birth might not be the same as nationality
213
+
214
+ t.references :city
215
+ t.references :region
216
+ t.references :country ## , null: false
217
+
218
+ t.references :nationality ## , null: false # by default assume same as country of birth (see above)
219
+
63
220
  t.timestamps
64
221
  end
65
222
 
223
+
224
+
66
225
  end # method up
67
226
 
68
227
  def down
@@ -1,4 +1,4 @@
1
1
 
2
2
  module WineDb
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
@@ -31,8 +31,17 @@ City = WorldDb::Model::City
31
31
 
32
32
  ## todo: get all models aliases (e.g. from console script)
33
33
 
34
- Wine = WineDb::Model::Wine
35
- Winery = WineDb::Model::Winery
34
+ Grape = WineDb::Model::Grape
35
+ Family = WineDb::Model::Family
36
+ Variety = WineDb::Model::Variety
37
+ Vineyard = WineDb::Model::Vineyard
38
+ Person = WineDb::Model::Person
39
+ Shop = WineDb::Model::Shop
40
+ Tavern = WineDb::Model::Tavern
41
+ Vintage = WineDb::Model::Vintage
42
+ Wine = WineDb::Model::Wine
43
+ Winery = WineDb::Model::Winery
44
+
36
45
 
37
46
 
38
47
  def setup_in_memory_db
@@ -63,14 +72,15 @@ end
63
72
  def fillup_in_memory_db
64
73
  ## add some counties
65
74
 
66
- at = Country.create!( key: 'at', title: 'Austria', code: 'AUT', pop: 0, area: 0 )
67
- n = Region.create!( key: 'n', title: 'Niederösterreich', country_id: at.id )
75
+ at = Country.create!( key: 'at', title: 'Austria', code: 'AUT', pop: 0, area: 0 )
76
+ n = Region.create!( key: 'n', title: 'Niederösterreich', country_id: at.id )
77
+ feuersbrunn = City.create!( key: 'feuersbrunn', title: 'Feuersbrunn', country_id: at.id, region_id: n.id )
68
78
 
69
79
  end
70
80
 
71
81
  setup_in_memory_db()
72
82
  fillup_in_memory_db()
73
83
 
74
- AT = Country.find_by_key!( 'at' )
75
- N = Region.find_by_key!( 'n' )
76
-
84
+ AT = Country.find_by_key!( 'at' )
85
+ N = Region.find_by_key!( 'n' )
86
+ FEUERSBRUNN = City.find_by_key!( 'feuersbrunn' )
@@ -87,6 +87,11 @@ class TestFixtureMatchers < MiniTest::Unit::TestCase
87
87
 
88
88
  wines_at = [
89
89
  'at-austria!/1--n-niederoesterreich--eastern/wines',
90
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/wines',
91
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/feuersbrunn--wines',
92
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/feuersbrunn/wines',
93
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/wagram--wines',
94
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/wagram/wines',
90
95
  'at-austria!/1--n-niederoesterreich--eastern/wagram--wines',
91
96
  'at-austria!/1--n-niederoesterreich--eastern/wagram--feuersbrunn--wines',
92
97
  'at-austria!/1--n-niederoesterreich--eastern/wagram--wagram--wines'
@@ -103,7 +108,10 @@ class TestFixtureMatchers < MiniTest::Unit::TestCase
103
108
  wineries_at = [
104
109
  'at-austria!/1--n-niederoesterreich--eastern/wineries',
105
110
  'at-austria!/1--n-niederoesterreich--eastern/wagram--wineries',
111
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/wineries',
106
112
  'at-austria!/1--n-niederoesterreich--eastern/wagram--feuersbrunn--wineries',
113
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/feuersbrunn--wineries',
114
+ 'at-austria!/1--n-niederoesterreich--eastern/wagram/feuersbrunn/wineries',
107
115
  'at-austria!/1--n-niederoesterreich--eastern/wagram--wagram--wineries'
108
116
  ]
109
117
 
@@ -117,4 +125,30 @@ class TestFixtureMatchers < MiniTest::Unit::TestCase
117
125
  end # method test_wine_region
118
126
 
119
127
 
128
+ def test_misc
129
+ vineyards = 'at-austria!/1--n-niederoesterreich--eastern/wagram/feuersbrunn--vineyards'
130
+ taverns = 'at-austria!/1--n-niederoesterreich--eastern/wagram/feuersbrunn--taverns'
131
+ shops = 'at-austria!/1--n-niederoesterreich--eastern/wagram/shops'
132
+
133
+ found = match_vineyards_for_country_n_region( vineyards ) do |country_key,region_key|
134
+ assert( country_key == 'at')
135
+ assert( region_key == 'n' )
136
+ end
137
+ assert( found == true )
138
+
139
+ found = match_taverns_for_country_n_region( taverns ) do |country_key,region_key|
140
+ assert( country_key == 'at')
141
+ assert( region_key == 'n' )
142
+ end
143
+ assert( found == true )
144
+
145
+ found = match_shops_for_country_n_region( shops ) do |country_key,region_key|
146
+ assert( country_key == 'at')
147
+ assert( region_key == 'n' )
148
+ end
149
+ assert( found == true )
150
+ end
151
+
152
+
153
+
120
154
  end # class TestFixtureMatchers
@@ -11,13 +11,51 @@ require 'helper'
11
11
 
12
12
  class TestModels < MiniTest::Unit::TestCase
13
13
 
14
- def test_load_wine_values
14
+ def setup # runs before every test
15
+ WineDb.delete! # always clean-out tables
16
+ end
17
+
18
+ def test_worlddb_assocs
19
+ assert_equal 0, AT.wines.count
20
+ assert_equal 0, AT.wineries.count
21
+ assert_equal 0, AT.taverns.count
22
+ assert_equal 0, AT.shops.count
23
+
24
+ assert_equal 0, N.wines.count
25
+ assert_equal 0, N.wineries.count
26
+ assert_equal 0, N.taverns.count
27
+ assert_equal 0, N.shops.count
28
+
29
+ assert_equal 0, FEUERSBRUNN.wines.count
30
+ assert_equal 0, FEUERSBRUNN.wineries.count
31
+ assert_equal 0, FEUERSBRUNN.taverns.count
32
+ assert_equal 0, FEUERSBRUNN.shops.count
33
+ assert_equal 0, FEUERSBRUNN.vineyards.count
34
+ end
35
+
15
36
 
37
+ def test_count
38
+ assert_equal 0, Grape.count
39
+ assert_equal 0, Family.count
40
+ assert_equal 0, Variety.count
41
+ assert_equal 0, Vineyard.count
42
+ assert_equal 0, Person.count
43
+ assert_equal 0, Shop.count
44
+ assert_equal 0, Tavern.count
45
+ assert_equal 0, Vintage.count
46
+ assert_equal 0, Wine.count
47
+ assert_equal 0, Winery.count
48
+
49
+ WineDb.tables # print stats
50
+ end
51
+
52
+
53
+ def test_load_wine_values
54
+
16
55
  key = 'gruenerveltlinerspiegel'
17
56
 
18
57
  values = [
19
58
  'Grüner Veltliner Spiegel',
20
- '12.3 %',
21
59
  'gv'
22
60
  ]
23
61
 
@@ -33,7 +71,6 @@ class TestModels < MiniTest::Unit::TestCase
33
71
  assert_equal wine.title, values[0]
34
72
  assert_equal wine.country_id, AT.id
35
73
  assert_equal wine.country.title, AT.title
36
- assert_equal wine.abv, 12.3
37
74
  end
38
75
 
39
76
  def test_load_winery_values
@@ -45,8 +82,7 @@ class TestModels < MiniTest::Unit::TestCase
45
82
  'Anton Bauer (1971)',
46
83
  'www.antonbauer.at',
47
84
  'Neufang 42 // 3483 Feuersbrunn',
48
- '25 ha', ### todo: make sure it will not get matched as tag
49
- 'tag'
85
+ '25 ha' ### todo: make sure it will not get matched as tag
50
86
  ]
51
87
 
52
88
  more_attribs = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winedb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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: 2014-03-02 00:00:00.000000000 Z
12
+ date: 2014-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &77127330 !ruby/object:Gem::Requirement
16
+ requirement: &81648500 !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: *77127330
24
+ version_requirements: *81648500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: worlddb
27
- requirement: &77126990 !ruby/object:Gem::Requirement
27
+ requirement: &81647750 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.7'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *77126990
35
+ version_requirements: *81647750
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gli
38
- requirement: &77126430 !ruby/object:Gem::Requirement
38
+ requirement: &81647430 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.5.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *77126430
46
+ version_requirements: *81647430
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &77126100 !ruby/object:Gem::Requirement
49
+ requirement: &81719370 !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: *77126100
57
+ version_requirements: *81719370
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &77125700 !ruby/object:Gem::Requirement
60
+ requirement: &81718560 !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: *77125700
68
+ version_requirements: *81718560
69
69
  description: winedb - wine.db command line tool
70
70
  email: winedb@googlegroups.com
71
71
  executables: []
@@ -78,13 +78,21 @@ files:
78
78
  - README.md
79
79
  - Rakefile
80
80
  - lib/winedb.rb
81
- - lib/winedb/models/city.rb
82
- - lib/winedb/models/country.rb
81
+ - lib/winedb/models/family.rb
83
82
  - lib/winedb/models/forward.rb
84
- - lib/winedb/models/region.rb
83
+ - lib/winedb/models/grape.rb
84
+ - lib/winedb/models/person.rb
85
+ - lib/winedb/models/shop.rb
85
86
  - lib/winedb/models/tag.rb
87
+ - lib/winedb/models/tavern.rb
88
+ - lib/winedb/models/variety.rb
89
+ - lib/winedb/models/vineyard.rb
90
+ - lib/winedb/models/vintage.rb
86
91
  - lib/winedb/models/wine.rb
87
92
  - lib/winedb/models/winery.rb
93
+ - lib/winedb/models/worlddb/city.rb
94
+ - lib/winedb/models/worlddb/country.rb
95
+ - lib/winedb/models/worlddb/region.rb
88
96
  - lib/winedb/reader.rb
89
97
  - lib/winedb/schema.rb
90
98
  - lib/winedb/version.rb
@@ -1,11 +0,0 @@
1
- module WorldDb
2
- module Model
3
-
4
- class City
5
- has_many :wines, class_name: 'WineDb::Model::Wine', foreign_key: 'city_id'
6
- has_many :wineries, class_name: 'WineDb::Model::Winery', foreign_key: 'city_id'
7
- end # class Country
8
-
9
-
10
- end # module Model
11
- end # module WorldDb
@@ -1,10 +0,0 @@
1
- module WorldDb
2
- module Model
3
-
4
- class Region
5
- has_many :wines, class_name: 'WineDb::Model::Wine', foreign_key: 'region_id'
6
- has_many :wineries, class_name: 'WineDb::Model::Winery', foreign_key: 'region_id'
7
- end # class Region
8
-
9
- end # module Model
10
- end # module WorldDb