winedb 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,10 @@ HISTORY.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
+ data/families.txt
6
+ data/grapes-red.txt
7
+ data/grapes-white.txt
8
+ data/setups/all.yml
5
9
  lib/winedb.rb
6
10
  lib/winedb/models/family.rb
7
11
  lib/winedb/models/forward.rb
@@ -23,4 +27,7 @@ lib/winedb/schema.rb
23
27
  lib/winedb/version.rb
24
28
  test/helper.rb
25
29
  test/test_fixture_matchers.rb
30
+ test/test_grapes.rb
26
31
  test/test_models.rb
32
+ test/test_wineries.rb
33
+ test/test_wines.rb
@@ -0,0 +1,40 @@
1
+
2
+ ww, White Wine
3
+ ## add subfamilies e.g. White Wine Varietal, White Wine Blend/Cuvée
4
+
5
+ rw, Red Wine
6
+ ## add subfamilies e.g. Red Wine Varietal, Red Wine Blend/Cuvée
7
+
8
+
9
+ Rosé Wine # -- what code to use ?? any conventions ???
10
+
11
+
12
+ dw, Dessert Wine (Sweet) # -- what code to use ?? any conventions ???
13
+
14
+ ## add
15
+ # [ba]
16
+ # Beerenauslese
17
+ #
18
+ # [tba]
19
+ # Trochenbeerenauslese
20
+ #
21
+ # Eiswein
22
+ # Ausbruch
23
+ #
24
+
25
+
26
+ fw, Fortified Wine # -- what code to use ?? any conventions ???
27
+ # add Port, Madeira, Sherry, Marsala etc.
28
+
29
+ sw, Sparkling Wine # -- what code to use ?? any conventions ???
30
+ # Champagne, Cava, Prosecco, etc.
31
+
32
+
33
+ xx, Other # -- what code to use ?? any convetion ??
34
+
35
+
36
+ #
37
+ #
38
+ # todo/check:
39
+ # use wine color? not the same as family in some case (is orthogonal?)
40
+ # e.g. for sparkling wine or dessert wine (red,rose,white possible?) - needed - why? why not?
@@ -0,0 +1,16 @@
1
+ ###################################
2
+ # Red Wine Styles / Types
3
+
4
+ zw, Zweigelt|Blauer Zweigelt|Rotburger
5
+ bf, Blaufränkisch
6
+ bp, Blauer Portugieser|Português Azul
7
+ bb, Blauburger
8
+ sl, St. Laurent|Sankt Laurent
9
+ pn, Pinot Noir|Blauburgunder|Blauer Spätburgunder
10
+ me, Merlot
11
+ cs, Cabernet Sauvignon
12
+ bw, Blauer Wildbacher ## Schilcher
13
+ ro, Roesler
14
+ sy, Syrah|Shiraz
15
+ cf, Cabernet Franc
16
+ ra, Ráthay
@@ -0,0 +1,35 @@
1
+ ###################################
2
+ # White Wine Styles / Types
3
+
4
+ gv, Grüner Veltliner|Weißgipfler
5
+ wr, Welschriesling
6
+ mt, Müller Thurgau|Rivaner
7
+ wb, Weißburgunder|Weißer Burgunder|Pinot Blanc|Klevner
8
+ rr, Riesling|Rheinriesling|Weißer Riesling
9
+ ch, Chardonnay|Morillon
10
+ sb, Sauvignon Blanc
11
+ nb, Neuburger
12
+ mk, Muskateller|Gelber Muskateller|Roter Muskateller
13
+ fv, Frühroter Veltliner|Malvasier
14
+ sr, Scheurebe|Sämling 88
15
+ mo, Muskat-Ottonel
16
+ tr, Traminer|Gelber Traminer|Gewürztraminer|Roter Traminer
17
+ bo, Bouvier
18
+ pg, Pinot Gris|Grauburgunder|Ruländer
19
+ rv, Roter Veltliner
20
+ gb, Goldburger
21
+ rg, Rotgipfler
22
+ zf, Zierfandler|Spätrot
23
+ sv, Sylvaner|Silvaner|Grüner Sylvaner
24
+ ju, Jubiläumsrebe
25
+ fu, Furmint
26
+
27
+
28
+ ##################
29
+ # what to do with non-official listed styles:
30
+ #
31
+ # - kr, Kerner ??? - de.wikipedia: Kerner_(Rebsorte)
32
+ # - rm, Rosenmuskateller ??? - de.wikipedia: Rosenmuskateller
33
+ # - se, Sémillon ??? - de.wikipedia: Sémillon
34
+ # -
35
+
@@ -0,0 +1,8 @@
1
+ ############################
2
+ # builtin seed data
3
+
4
+ data:
5
+ - grapes-red
6
+ - grapes-white
7
+ - families
8
+
@@ -47,6 +47,11 @@ module WineDb
47
47
  "#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
48
48
  end
49
49
 
50
+ def self.data_path
51
+ "#{root}/data"
52
+ end
53
+
54
+
50
55
  def self.create
51
56
  CreateDb.new.up
52
57
 
@@ -70,6 +75,10 @@ module WineDb
70
75
  read_setup( 'setups/all', include_path, opts )
71
76
  end # method read_all
72
77
 
78
+ def self.read_builtin
79
+ read_setup( 'setups/all', data_path )
80
+ end
81
+
73
82
  def self.delete!
74
83
  ## fix/todo: move into deleter class (see worlddb,sportdb etc.)
75
84
  Model::Grape.delete_all
@@ -5,7 +5,92 @@ module WineDb
5
5
 
6
6
  class Grape < ActiveRecord::Base
7
7
 
8
- ## to be done
8
+ extend TextUtils::TagHelper # will add self.find_tags, self.find_tags_in_attribs!, etc.
9
+
10
+ # NB: use extend - is_<type>? become class methods e.g. self.is_<type>? for use in
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.
13
+
14
+ has_many :taggings, :as => :taggable, class_name: 'WorldDb::Model::Tagging'
15
+ has_many :tags, :through => :taggings, class_name: 'WorldDb::Model::Tag'
16
+
17
+ validates :key, :format => { :with => /^[a-z][a-z0-9]+$/, :message => 'expected two or more lowercase letters a-z or 0-9 digits' }
18
+
19
+
20
+ def self.create_or_update_from_values( values, more_attribs={} )
21
+
22
+ attribs, more_values = find_key_n_title( values )
23
+ attribs = attribs.merge( more_attribs )
24
+
25
+ # check for optional values
26
+ Grape.create_or_update_from_attribs( attribs, more_values )
27
+ end
28
+
29
+
30
+ def self.create_or_update_from_attribs( attribs, values )
31
+
32
+ # fix: add/configure logger for ActiveRecord!!!
33
+ logger = LogKernel::Logger.root
34
+
35
+ value_tag_keys = []
36
+
37
+ ### check for "default" tags - that is, if present attribs[:tags] remove from hash
38
+ value_tag_keys += find_tags_in_attribs!( attribs )
39
+
40
+ ## check for optional values
41
+ values.each_with_index do |value,index|
42
+ if match_year( value ) do |num| # founded/established year e.g. 1776
43
+ attribs[ :since ] = num
44
+ end
45
+ elsif match_website( value ) do |website| # check for url/internet address e.g. www.ottakringer.at
46
+ attribs[ :web ] = website
47
+ end
48
+ elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
49
+ logger.debug " found tags: >>#{value}<<"
50
+ value_tag_keys += find_tags( value )
51
+ else
52
+ # issue warning: unknown type for value
53
+ logger.warn "unknown type for value >#{value}< - key #{attribs[:key]}"
54
+ end
55
+ end # each value
56
+
57
+ rec = Grape.find_by_key( attribs[ :key ] )
58
+
59
+ if rec.present?
60
+ logger.debug "update Grape #{rec.id}-#{rec.key}:"
61
+ else
62
+ logger.debug "create Grape:"
63
+ rec = Grape.new
64
+ end
65
+
66
+ logger.debug attribs.to_json
67
+
68
+ rec.update_attributes!( attribs )
69
+
70
+ ##################
71
+ # add taggings
72
+
73
+ if value_tag_keys.size > 0
74
+
75
+ value_tag_keys.uniq! # remove duplicates
76
+ logger.debug " adding #{value_tag_keys.size} taggings: >>#{value_tag_keys.join('|')}<<..."
77
+
78
+ ### fix/todo: check tag_ids and only update diff (add/remove ids)
79
+
80
+ value_tag_keys.each do |key|
81
+ tag = Tag.find_by_key( key )
82
+ if tag.nil? # create tag if it doesn't exit
83
+ logger.debug " creating tag >#{key}<"
84
+ tag = Tag.create!( key: key )
85
+ end
86
+ rec.tags << tag
87
+ end
88
+ end
89
+
90
+ rec # NB: return created or updated obj
91
+
92
+ end # method create_or_update_from_values
93
+
9
94
 
10
95
  end # class Grape
11
96
 
@@ -131,7 +131,11 @@ class Reader
131
131
 
132
132
  def load( name )
133
133
 
134
- if match_wines_for_country_n_region( name ) do |country_key, region_key|
134
+ # grapes - allow e.g.
135
+ # - /grapes or /grapes-red or /grapes-white
136
+ if name =~ /(^|\/)grapes(-(red|white))?$/
137
+ load_grapes( name )
138
+ elsif match_wines_for_country_n_region( name ) do |country_key, region_key|
135
139
  ### fix: use region_key too
136
140
  load_wines_for_country( country_key, name )
137
141
  end
@@ -152,6 +156,27 @@ class Reader
152
156
  end
153
157
 
154
158
 
159
+ def load_grapes( name, more_attribs={} )
160
+ if name =~ /(^|\/)grapes-red$/
161
+ more_attribs[ :red ] = true
162
+ elsif name =~ /(^|\/)grapes-white$/
163
+ more_attribs[ :white ] = true
164
+ else
165
+ # do nothing
166
+ end
167
+
168
+ load_grapes_worker( name, more_attribs )
169
+ end
170
+
171
+ def load_grapes_worker( name, more_attribs={} )
172
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
173
+
174
+ reader.each_line do |new_attributes, values|
175
+ Grape.create_or_update_from_attribs( new_attributes, values )
176
+ end # each_line
177
+ end
178
+
179
+
155
180
  def load_wines_for_country( country_key, name, more_attribs={} )
156
181
  country = Country.find_by_key!( country_key )
157
182
  logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
@@ -164,6 +189,7 @@ class Reader
164
189
  end
165
190
 
166
191
 
192
+
167
193
  def load_wines_worker( name, more_attribs={} )
168
194
  reader = ValuesReaderV2.new( name, include_path, more_attribs )
169
195
 
@@ -89,6 +89,7 @@ create_table :grapes do |t|
89
89
  t.boolean :red, null: false, default: false
90
90
  t.boolean :white, null: false, default: false
91
91
 
92
+ t.integer :since
92
93
  t.string :web # optional web page
93
94
  t.string :wikipedia # optional wiki(pedia page)
94
95
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module WineDb
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  end
5
5
 
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'helper'
5
+
6
+
7
+ class TestGrapes < MiniTest::Unit::TestCase
8
+
9
+ def setup # runs before every test
10
+ PersonDb.delete!
11
+ WineDb.delete! # always clean-out tables
12
+ end
13
+
14
+
15
+ def test_load_grape_values
16
+
17
+ key = 'gv'
18
+
19
+ values = [
20
+ key,
21
+ 'Grüner Veltliner',
22
+ 'gv'
23
+ ]
24
+
25
+ more_attribs = {
26
+ white: true
27
+ }
28
+
29
+ grape = Grape.create_or_update_from_values( values, more_attribs )
30
+
31
+ grape2 = Grape.find_by_key!( key )
32
+ assert_equal grape2.id, grape.id
33
+
34
+ assert_equal values[1], grape.title
35
+ assert_equal true, grape.white
36
+ assert_equal false, grape.red
37
+ end
38
+
39
+
40
+ end # class TestGrapes
41
+
@@ -1,10 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_helper.rb
6
- # or better
7
- # rake test
8
3
 
9
4
  require 'helper'
10
5
 
@@ -54,61 +49,20 @@ class TestModels < MiniTest::Unit::TestCase
54
49
  PersonDb.tables
55
50
  end
56
51
 
52
+ def test_builtin
53
+ WineDb.read_builtin
57
54
 
58
- def test_load_wine_values
59
-
60
- key = 'gruenerveltlinerspiegel'
55
+ gv = Grape.find_by_key!( 'gv' )
56
+ assert_equal 'gv', gv.key
57
+ assert_equal 'Grüner Veltliner', gv.title
58
+ assert_equal true, gv.white
59
+ assert_equal false, gv.red
61
60
 
62
- values = [
63
- 'Grüner Veltliner Spiegel',
64
- 'gv'
65
- ]
66
-
67
- more_attribs = {
68
- country_id: AT.id
69
- }
70
-
71
- wine = Wine.create_or_update_from_values( values, more_attribs )
72
-
73
- wine2 = Wine.find_by_key!( key )
74
- assert_equal wine2.id, wine.id
75
-
76
- assert_equal values[0], wine.title
77
- assert_equal AT.id, wine.country_id
78
- assert_equal AT.title, wine.country.title
79
- end
80
-
81
-
82
- def test_load_winery_values
83
-
84
- key = 'antonbauer'
85
-
86
- values = [
87
- key,
88
- 'Anton Bauer (1971)',
89
- 'www.antonbauer.at',
90
- 'Neufang 42 // 3483 Feuersbrunn',
91
- '25 ha' ### todo: make sure it will not get matched as tag
92
- ]
93
-
94
- more_attribs = {
95
- country_id: AT.id
96
- }
97
-
98
- wy = Winery.create_or_update_from_values( values, more_attribs )
99
-
100
- wy2 = Winery.find_by_key!( key )
101
- assert_equal wy.id, wy2.id
102
-
103
- assert_equal 'Anton Bauer', wy.title
104
- assert_equal AT.id, wy.country_id
105
- assert_equal AT.title, wy.country.title
106
- assert_equal 'www.antonbauer.at', wy.web
107
- assert_equal 'Neufang 42 // 3483 Feuersbrunn', wy.address
108
-
109
- ## check for auto-create person
110
- p = Person.find_by_key!( 'antonbauer' )
111
- assert_equal 'Anton Bauer', p.name
61
+ zw = Grape.find_by_key!( 'zw' )
62
+ assert_equal 'zw', zw.key
63
+ assert_equal 'Zweigelt', zw.title
64
+ assert_equal false, zw.white
65
+ assert_equal true, zw.red
112
66
  end
113
67
 
114
68
 
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+
6
+ class TestWineries < MiniTest::Unit::TestCase
7
+
8
+ def setup # runs before every test
9
+ PersonDb.delete!
10
+ WineDb.delete! # always clean-out tables
11
+ end
12
+
13
+
14
+ def test_load_winery_values
15
+
16
+ key = 'antonbauer'
17
+
18
+ values = [
19
+ key,
20
+ 'Anton Bauer (1971)',
21
+ 'www.antonbauer.at',
22
+ 'Neufang 42 // 3483 Feuersbrunn',
23
+ '25 ha' ### todo: make sure it will not get matched as tag
24
+ ]
25
+
26
+ more_attribs = {
27
+ country_id: AT.id
28
+ }
29
+
30
+ wy = Winery.create_or_update_from_values( values, more_attribs )
31
+
32
+ wy2 = Winery.find_by_key!( key )
33
+ assert_equal wy.id, wy2.id
34
+
35
+ assert_equal 'Anton Bauer', wy.title
36
+ assert_equal AT.id, wy.country_id
37
+ assert_equal AT.title, wy.country.title
38
+ assert_equal 'www.antonbauer.at', wy.web
39
+ assert_equal 'Neufang 42 // 3483 Feuersbrunn', wy.address
40
+
41
+ ## check for auto-create person
42
+ p = Person.find_by_key!( 'antonbauer' )
43
+ assert_equal 'Anton Bauer', p.name
44
+ end
45
+
46
+
47
+ end # class TestModels
48
+
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'helper'
5
+
6
+
7
+ class TestWines < MiniTest::Unit::TestCase
8
+
9
+ def setup # runs before every test
10
+ PersonDb.delete!
11
+ WineDb.delete! # always clean-out tables
12
+ end
13
+
14
+
15
+ def test_load_wine_values
16
+
17
+ key = 'gruenerveltlinerspiegel'
18
+
19
+ values = [
20
+ 'Grüner Veltliner Spiegel',
21
+ 'gv'
22
+ ]
23
+
24
+ more_attribs = {
25
+ country_id: AT.id
26
+ }
27
+
28
+ wine = Wine.create_or_update_from_values( values, more_attribs )
29
+
30
+ wine2 = Wine.find_by_key!( key )
31
+ assert_equal wine2.id, wine.id
32
+
33
+ assert_equal values[0], wine.title
34
+ assert_equal AT.id, wine.country_id
35
+ assert_equal AT.title, wine.country.title
36
+ end
37
+
38
+
39
+ end # class TestWines
40
+
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.5
4
+ version: 0.1.6
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-05 00:00:00.000000000 Z
12
+ date: 2014-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &78517140 !ruby/object:Gem::Requirement
16
+ requirement: &77482170 !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: *78517140
24
+ version_requirements: *77482170
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: worlddb
27
- requirement: &78516770 !ruby/object:Gem::Requirement
27
+ requirement: &77481300 !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: *78516770
35
+ version_requirements: *77481300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: persondb
38
- requirement: &78516440 !ruby/object:Gem::Requirement
38
+ requirement: &77480750 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *78516440
46
+ version_requirements: *77480750
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: gli
49
- requirement: &78515940 !ruby/object:Gem::Requirement
49
+ requirement: &77479900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.5.6
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *78515940
57
+ version_requirements: *77479900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &78515510 !ruby/object:Gem::Requirement
60
+ requirement: &77581620 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.10'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *78515510
68
+ version_requirements: *77581620
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hoe
71
- requirement: &78514750 !ruby/object:Gem::Requirement
71
+ requirement: &77581310 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '3.3'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *78514750
79
+ version_requirements: *77581310
80
80
  description: winedb - wine.db command line tool
81
81
  email: winedb@googlegroups.com
82
82
  executables: []
@@ -88,6 +88,10 @@ files:
88
88
  - Manifest.txt
89
89
  - README.md
90
90
  - Rakefile
91
+ - data/families.txt
92
+ - data/grapes-red.txt
93
+ - data/grapes-white.txt
94
+ - data/setups/all.yml
91
95
  - lib/winedb.rb
92
96
  - lib/winedb/models/family.rb
93
97
  - lib/winedb/models/forward.rb
@@ -109,7 +113,10 @@ files:
109
113
  - lib/winedb/version.rb
110
114
  - test/helper.rb
111
115
  - test/test_fixture_matchers.rb
116
+ - test/test_grapes.rb
112
117
  - test/test_models.rb
118
+ - test/test_wineries.rb
119
+ - test/test_wines.rb
113
120
  - .gemtest
114
121
  homepage: https://github.com/geraldb/wine.db.ruby
115
122
  licenses:
@@ -139,5 +146,8 @@ signing_key:
139
146
  specification_version: 3
140
147
  summary: winedb - wine.db command line tool
141
148
  test_files:
149
+ - test/test_wines.rb
142
150
  - test/test_models.rb
151
+ - test/test_grapes.rb
152
+ - test/test_wineries.rb
143
153
  - test/test_fixture_matchers.rb