winedb 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/winedb/models/wine.rb +7 -1
- data/lib/winedb/models/winery.rb +64 -0
- data/lib/winedb/version.rb +2 -1
- data/test/test_models.rb +22 -12
- metadata +13 -13
data/lib/winedb/models/wine.rb
CHANGED
@@ -67,7 +67,13 @@ class Wine < ActiveRecord::Base
|
|
67
67
|
elsif match_website( value ) do |website| # check for url/internet address e.g. www.ottakringer.at
|
68
68
|
attribs[ :web ] = website
|
69
69
|
end
|
70
|
-
|
70
|
+
elsif value =~ /^winery:/ ## winery:<key> e.g. winery:antonbauer
|
71
|
+
winery_key = value[7..-1].strip ## cut off by: prefix
|
72
|
+
winery = Winery.find_by_key!( winery_key )
|
73
|
+
attribs[ :winery_id ] = winery.id
|
74
|
+
|
75
|
+
|
76
|
+
# -- todo/fix: move to vintage (that is, abv depends on year)
|
71
77
|
# elsif match_abv( value ) do |num| # abv (alcohol by volume)
|
72
78
|
# # nb: also allows leading < e.g. <0.5%
|
73
79
|
# attribs[ :abv ] = num
|
data/lib/winedb/models/winery.rb
CHANGED
@@ -46,6 +46,38 @@ class Winery < ActiveRecord::Base
|
|
46
46
|
## check for grades (e.g. ***/**/*) in titles (will add new_attributes[:grade] to hash)
|
47
47
|
## if grade missing; set default to 4; lets us update overwrite 1,2,3 values on update
|
48
48
|
new_attributes[ :grade ] ||= 4
|
49
|
+
|
50
|
+
####
|
51
|
+
## check if :title or :synonyms includes person name e.g. ends w/ (????)
|
52
|
+
## patch and auto-add person
|
53
|
+
### --todo/fix: move code into find_key_n_title (for reuse!!!) !!!!!!
|
54
|
+
|
55
|
+
titles = [ new_attributes[:title] ]
|
56
|
+
titles += new_attributes[:synonyms].split('|') if new_attributes[:synonyms]
|
57
|
+
|
58
|
+
persons = []
|
59
|
+
|
60
|
+
titles = titles.map do |title_raw|
|
61
|
+
title = title_raw.strip
|
62
|
+
### todo: add support for name synonyms e.g. separated by * ascii or <bullet>
|
63
|
+
if title =~ /\s+\([\d?]{4}\)$/ ## -- allow (19??) or (????) or (2100) etc.
|
64
|
+
logger.debug " found person >#{title}< in title"
|
65
|
+
### cut-off year
|
66
|
+
person_name = title[0...-6].strip ## cut-off enclosed year and spaces
|
67
|
+
person_year = $1.to_s
|
68
|
+
## todo: year if person_year is all digits ? if not use nil
|
69
|
+
|
70
|
+
persons << [person_name, person_year]
|
71
|
+
person_name # note: return person_name as new title (that is, title w/ year cut-off)
|
72
|
+
else
|
73
|
+
title # pass through as is
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
new_attributes[:title] = titles[0]
|
78
|
+
new_attributes[:synonyms] = titles[1..-1].join('|') if titles.size > 1
|
79
|
+
|
80
|
+
|
49
81
|
|
50
82
|
### check for "default" tags - that is, if present new_attributes[:tags] remove from hash
|
51
83
|
value_tag_keys += find_tags_in_attribs!( new_attributes )
|
@@ -111,6 +143,38 @@ class Winery < ActiveRecord::Base
|
|
111
143
|
rec.update_attributes!( new_attributes )
|
112
144
|
|
113
145
|
|
146
|
+
#################################
|
147
|
+
# auto-add person if present
|
148
|
+
|
149
|
+
if persons.size > 0
|
150
|
+
persons.each do |person|
|
151
|
+
|
152
|
+
person_name = person[0]
|
153
|
+
person_key = TextUtils.title_to_key( person_name )
|
154
|
+
|
155
|
+
person_attributes = {
|
156
|
+
name: person_name
|
157
|
+
}
|
158
|
+
|
159
|
+
person_rec = Person.find_by_key( person_key )
|
160
|
+
if person_rec.present?
|
161
|
+
logger.debug " auto-update Person #{person_rec.id}-#{person_rec.key}:"
|
162
|
+
else
|
163
|
+
logger.debug " auto-create Person:"
|
164
|
+
person_rec =Person.new
|
165
|
+
person_attributes[ :key ] = person_key
|
166
|
+
end
|
167
|
+
|
168
|
+
logger.debug person_attributes.to_json
|
169
|
+
|
170
|
+
person_rec.update_attributes!( person_attributes )
|
171
|
+
|
172
|
+
## todo: add winery_id reference to person !!!!
|
173
|
+
### add person_id reference to winery!!!
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
114
178
|
##############################
|
115
179
|
# auto-add city if not present and country n region present
|
116
180
|
|
data/lib/winedb/version.rb
CHANGED
data/test/test_models.rb
CHANGED
@@ -12,9 +12,11 @@ require 'helper'
|
|
12
12
|
class TestModels < MiniTest::Unit::TestCase
|
13
13
|
|
14
14
|
def setup # runs before every test
|
15
|
+
PersonDb.delete!
|
15
16
|
WineDb.delete! # always clean-out tables
|
16
17
|
end
|
17
|
-
|
18
|
+
|
19
|
+
|
18
20
|
def test_worlddb_assocs
|
19
21
|
assert_equal 0, AT.wines.count
|
20
22
|
assert_equal 0, AT.wineries.count
|
@@ -35,18 +37,21 @@ class TestModels < MiniTest::Unit::TestCase
|
|
35
37
|
|
36
38
|
|
37
39
|
def test_count
|
40
|
+
assert_equal 0, Person.count
|
41
|
+
|
38
42
|
assert_equal 0, Grape.count
|
39
43
|
assert_equal 0, Family.count
|
40
44
|
assert_equal 0, Variety.count
|
41
45
|
assert_equal 0, Vineyard.count
|
42
|
-
assert_equal 0, Person.count
|
43
46
|
assert_equal 0, Shop.count
|
44
47
|
assert_equal 0, Tavern.count
|
45
48
|
assert_equal 0, Vintage.count
|
46
49
|
assert_equal 0, Wine.count
|
47
50
|
assert_equal 0, Winery.count
|
48
51
|
|
49
|
-
|
52
|
+
# print stats
|
53
|
+
WineDb.tables
|
54
|
+
PersonDb.tables
|
50
55
|
end
|
51
56
|
|
52
57
|
|
@@ -66,13 +71,14 @@ class TestModels < MiniTest::Unit::TestCase
|
|
66
71
|
wine = Wine.create_or_update_from_values( values, more_attribs )
|
67
72
|
|
68
73
|
wine2 = Wine.find_by_key!( key )
|
69
|
-
assert_equal
|
74
|
+
assert_equal wine2.id, wine.id
|
70
75
|
|
71
|
-
assert_equal
|
72
|
-
assert_equal wine.country_id
|
73
|
-
assert_equal wine.country.title
|
76
|
+
assert_equal values[0], wine.title
|
77
|
+
assert_equal AT.id, wine.country_id
|
78
|
+
assert_equal AT.title, wine.country.title
|
74
79
|
end
|
75
80
|
|
81
|
+
|
76
82
|
def test_load_winery_values
|
77
83
|
|
78
84
|
key = 'antonbauer'
|
@@ -94,11 +100,15 @@ class TestModels < MiniTest::Unit::TestCase
|
|
94
100
|
wy2 = Winery.find_by_key!( key )
|
95
101
|
assert_equal wy.id, wy2.id
|
96
102
|
|
97
|
-
assert_equal wy.title
|
98
|
-
assert_equal wy.country_id
|
99
|
-
assert_equal wy.country.title
|
100
|
-
assert_equal
|
101
|
-
assert_equal
|
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
|
102
112
|
end
|
103
113
|
|
104
114
|
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2014-03-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &78517140 !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: *78517140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: worlddb
|
27
|
-
requirement: &
|
27
|
+
requirement: &78516770 !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: *
|
35
|
+
version_requirements: *78516770
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: persondb
|
38
|
-
requirement: &
|
38
|
+
requirement: &78516440 !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: *
|
46
|
+
version_requirements: *78516440
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: gli
|
49
|
-
requirement: &
|
49
|
+
requirement: &78515940 !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: *
|
57
|
+
version_requirements: *78515940
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rdoc
|
60
|
-
requirement: &
|
60
|
+
requirement: &78515510 !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: *
|
68
|
+
version_requirements: *78515510
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hoe
|
71
|
-
requirement: &
|
71
|
+
requirement: &78514750 !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: *
|
79
|
+
version_requirements: *78514750
|
80
80
|
description: winedb - wine.db command line tool
|
81
81
|
email: winedb@googlegroups.com
|
82
82
|
executables: []
|