beerdb 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/beerdb/reader.rb +21 -41
- data/lib/beerdb/version.rb +1 -1
- data/lib/beerdb.rb +14 -27
- metadata +23 -23
data/lib/beerdb/reader.rb
CHANGED
@@ -13,9 +13,6 @@ module Matcher
|
|
13
13
|
match_xxx_for_country_n_region( name, 'beers', &blk )
|
14
14
|
end
|
15
15
|
|
16
|
-
## todo: add match_brewpubs ???
|
17
|
-
## - autoadd brewpub flag!! use more_attribs??
|
18
|
-
|
19
16
|
def match_breweries_for_country( name, &blk )
|
20
17
|
match_xxx_for_country( name, 'breweries', &blk )
|
21
18
|
end
|
@@ -24,6 +21,16 @@ module Matcher
|
|
24
21
|
match_xxx_for_country_n_region( name, 'breweries', &blk )
|
25
22
|
end
|
26
23
|
|
24
|
+
## todo: autoadd brewpub flag!! use more_attribs??
|
25
|
+
def match_brewpubs_for_country( name, &blk )
|
26
|
+
match_xxx_for_country( name, 'brewpubs', &blk )
|
27
|
+
end
|
28
|
+
|
29
|
+
def match_brewpubs_for_country_n_region( name, &blk )
|
30
|
+
match_xxx_for_country_n_region( name, 'brewpubs', &blk )
|
31
|
+
end
|
32
|
+
|
33
|
+
|
27
34
|
end # module Matcher
|
28
35
|
|
29
36
|
|
@@ -45,7 +52,7 @@ class Reader
|
|
45
52
|
|
46
53
|
|
47
54
|
def load_setup( name )
|
48
|
-
path = "#{include_path}/#{name}.
|
55
|
+
path = "#{include_path}/#{name}.txt"
|
49
56
|
|
50
57
|
logger.info "parsing data '#{name}' (#{path})..."
|
51
58
|
|
@@ -57,14 +64,10 @@ class Reader
|
|
57
64
|
end # method load_setup
|
58
65
|
|
59
66
|
|
67
|
+
|
60
68
|
def load( name )
|
61
69
|
|
62
|
-
if name
|
63
|
-
load_brewery_prod( name )
|
64
|
-
elsif name =~ /\/([a-z]{2})\.wikipedia/ # e.g. de.wikipedia
|
65
|
-
# auto-add required lang e.g. de or en etc.
|
66
|
-
load_brewery_wikipedia( $1, name )
|
67
|
-
elsif match_beers_for_country_n_region( name ) do |country_key, region_key|
|
70
|
+
if match_beers_for_country_n_region( name ) do |country_key, region_key|
|
68
71
|
load_beers_for_country_n_region( country_key, region_key, name )
|
69
72
|
end
|
70
73
|
elsif match_beers_for_country( name ) do |country_key|
|
@@ -76,6 +79,14 @@ class Reader
|
|
76
79
|
elsif match_breweries_for_country( name ) do |country_key|
|
77
80
|
load_breweries_for_country( country_key, name )
|
78
81
|
end
|
82
|
+
elsif match_brewpubs_for_country_n_region( name ) do |country_key, region_key|
|
83
|
+
## todo: autoadd brewpub flag!! use more_attribs??
|
84
|
+
load_breweries_for_country_n_region( country_key, region_key, name )
|
85
|
+
end
|
86
|
+
elsif match_brewpubs_for_country( name ) do |country_key|
|
87
|
+
## todo: autoadd brewpub flag!! use more_attribs??
|
88
|
+
load_breweries_for_country( country_key, name )
|
89
|
+
end
|
79
90
|
else
|
80
91
|
logger.error "unknown beer.db fixture type >#{name}<"
|
81
92
|
# todo/fix: exit w/ error
|
@@ -83,37 +94,6 @@ class Reader
|
|
83
94
|
end
|
84
95
|
|
85
96
|
|
86
|
-
def load_brewery_wikipedia( lang_key, name )
|
87
|
-
reader = HashReaderV2.new( name, include_path )
|
88
|
-
|
89
|
-
reader.each do |key, value|
|
90
|
-
brewery = Brewery.find_by_key!( key )
|
91
|
-
|
92
|
-
wikipedia = "#{lang_key}.wikipedia.org/wiki/#{value.strip}"
|
93
|
-
logger.debug " adding #{key} => >#{wikipedia}<"
|
94
|
-
brewery.wikipedia = wikipedia
|
95
|
-
brewery.save!
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
def load_brewery_prod( name )
|
101
|
-
reader = HashReaderV2.new( name, include_path )
|
102
|
-
|
103
|
-
reader.each do |key, value|
|
104
|
-
brewery = Brewery.find_by_key!( key )
|
105
|
-
|
106
|
-
if value =~ /(?:([0-9][0-9_ ]+[0-9]|[0-9]{1,2})\s*hl)/ # e.g. 20_0000 hl or 50hl etc.
|
107
|
-
prod = $1.gsub(/[ _]/, '').to_i
|
108
|
-
logger.debug " adding #{key} => >#{prod}<"
|
109
|
-
brewery.prod = prod
|
110
|
-
brewery.save!
|
111
|
-
else
|
112
|
-
logger.warn " unknown type for brewery prod value >#{value}<; regex pattern match failed"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
97
|
def load_beers_for_country_n_region( country_key, region_key, name, more_attribs={} )
|
118
98
|
country = Country.find_by_key!( country_key )
|
119
99
|
logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
|
data/lib/beerdb/version.rb
CHANGED
data/lib/beerdb.rb
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
|
6
6
|
# core and stlibs
|
7
7
|
|
8
|
+
## stdlibs
|
9
|
+
# -- get required already by worlddb (remove ??)
|
10
|
+
|
8
11
|
require 'yaml'
|
9
12
|
require 'pp'
|
10
13
|
require 'logger'
|
@@ -14,10 +17,11 @@ require 'erb'
|
|
14
17
|
|
15
18
|
# 3rd party gems / libs
|
16
19
|
|
17
|
-
|
20
|
+
# -- get required by worlddb
|
21
|
+
# require 'active_record' ## todo: add sqlite3? etc.
|
22
|
+
# require 'logutils'
|
23
|
+
# require 'textutils'
|
18
24
|
|
19
|
-
require 'logutils'
|
20
|
-
require 'textutils'
|
21
25
|
require 'worlddb'
|
22
26
|
|
23
27
|
######################
|
@@ -176,7 +180,7 @@ end
|
|
176
180
|
|
177
181
|
# our own code
|
178
182
|
|
179
|
-
require 'beerdb/version'
|
183
|
+
require 'beerdb/version' ## version always goes first
|
180
184
|
|
181
185
|
require 'beerdb/models/forward'
|
182
186
|
require 'beerdb/models/country'
|
@@ -191,7 +195,9 @@ require 'beerdb/models/drink' # db model extensions - move to its own addon
|
|
191
195
|
require 'beerdb/models/bookmark' # db model extensions - move to its own addon gem?
|
192
196
|
require 'beerdb/models/note' # db model extensions - move to its own addon gem?
|
193
197
|
|
194
|
-
|
198
|
+
|
199
|
+
## add backwards compatible namespace
|
200
|
+
## todo: move to forward -- check sportdb/worlddb convention ??
|
195
201
|
module BeerDb
|
196
202
|
Models = Model
|
197
203
|
end
|
@@ -230,28 +236,7 @@ module BeerDb
|
|
230
236
|
CreateDbExtrasDrinks.new.up
|
231
237
|
CreateDbExtrasNotes.new.up
|
232
238
|
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
module CodeReaderContext
|
239
|
-
# make models available w/o namespace
|
240
|
-
# e.g. lets you use Beer instead of BeerDb::Models::Beer
|
241
|
-
include BeerDb::Models # check does it work w/ alias e.g. Models == Model
|
242
|
-
## <evaluated code here>
|
243
|
-
end
|
244
|
-
|
245
|
-
def self.load( name, include_path='.' ) # NB: pass in w/o .rb extension e.g use users etc.
|
246
|
-
path = "#{include_path}/#{name}.rb"
|
247
|
-
|
248
|
-
puts "*** loading seed data '#{name}' (#{path})..."
|
249
|
-
|
250
|
-
::CodeReader.new( path ).eval( CodeReaderContext )
|
251
|
-
## nb: will get evaluated in context of passed in module like
|
252
|
-
## module CodeReaderContext
|
253
|
-
## <seed code here>
|
254
|
-
## end
|
239
|
+
ConfDb::Model::Prop.create!( key: 'db.schema.beer.version', value: VERSION )
|
255
240
|
end
|
256
241
|
|
257
242
|
|
@@ -282,6 +267,8 @@ module BeerDb
|
|
282
267
|
Stats.new.tables
|
283
268
|
end
|
284
269
|
|
270
|
+
###
|
271
|
+
# fix: (re)use ConfDb.props
|
285
272
|
def self.props
|
286
273
|
Stats.new.props
|
287
274
|
end
|
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.9.
|
4
|
+
version: 0.9.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2014-10-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: props
|
16
|
-
requirement: &
|
16
|
+
requirement: &77761980 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *77761980
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: logutils
|
27
|
-
requirement: &
|
27
|
+
requirement: &77761760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *77761760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: textutils
|
38
|
-
requirement: &
|
38
|
+
requirement: &77761510 !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: *77761510
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: worlddb
|
49
|
-
requirement: &
|
49
|
+
requirement: &77761150 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.0.2
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *77761150
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: tagutils
|
60
|
-
requirement: &
|
60
|
+
requirement: &77760800 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *77760800
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activerecord-utils
|
71
|
-
requirement: &
|
71
|
+
requirement: &77760460 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *77760460
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: fetcher
|
82
|
-
requirement: &
|
82
|
+
requirement: &77760170 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0.3'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *77760170
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: gli
|
93
|
-
requirement: &
|
93
|
+
requirement: &77759820 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 2.5.6
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *77759820
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: activerecord
|
104
|
-
requirement: &
|
104
|
+
requirement: &77759280 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *77759280
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rdoc
|
115
|
-
requirement: &
|
115
|
+
requirement: &77758880 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ~>
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '4.0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *77758880
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: hoe
|
126
|
-
requirement: &
|
126
|
+
requirement: &77758470 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ~>
|
@@ -131,7 +131,7 @@ dependencies:
|
|
131
131
|
version: '3.12'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *77758470
|
135
135
|
description: beerdb - beer.db command line tool
|
136
136
|
email: beerdb@googlegroups.com
|
137
137
|
executables:
|