-
Notifications
You must be signed in to change notification settings - Fork 2
/
beer_db_intro.pdf.html
505 lines (358 loc) · 12.1 KB
/
beer_db_intro.pdf.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>beer.db - Using Open Beer & Brewery Data in Ruby</title>
<style>
html, body { margin: 0; padding: 0; }
body { font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; }
a:link, a:visited { color: black; }
h1 { font-size: 30pt; }
h2 { font-size: 28pt; }
h3 { font-size: 25pt; }
p, li, dt, dd, td, th { font-size: 18pt; }
pre { font-size: 14pt; }
pre.small { font-size: 11pt; }
pre.code {
background-color: azure;
padding: 5px;
}
ul { list-style-type: square; }
.center { text-align: center; }
.slide { page-break-after: always;
min-height: 100mm;
padding: 40px;
border: 1px dotted black;
/*
background: -moz-linear-gradient( top, maroon, red);
*/
}
pre {
padding: 4px 4px 4px 4px;
border-top: #bbb 1px solid;
border-bottom: #bbb 1px solid;
background: #f3f3f3;
}
/*
for princexml (CSS3 paged media support)
@page { size: A4 landscape }
*/
</style>
</head>
<body>
<div class="presentation">
<div class='slide '>
<!-- === begin markdown block =====================================================
generated by markdown 1.0.0 on Ruby 1.9.2 (2011-07-09) [i386-mingw32]
on 2013-04-12 16:15:24 +0200 with Markdown engine redcarpet (2.1.1) w/ HTML render
using extensions: [no_intra_emphasis, fenced_code_blocks, tables, strikethrough]
-->
<!-- _S9SLIDE_ -->
<h1><code>beer.db</code> - Using Open Beer & Brewery Data in Ruby</h1>
<h3>Agenda</h3>
<ul>
<li>What's <code>beer.db</code>?</li>
<li>Example: Breweries - <code>breweries.txt</code></li>
<li>Example: Beers - <code>beers.txt</code></li>
<li>How to use <code>beer.db</code> in Ruby</li>
<li>What's <code>world.db</code>?</li>
<li>How to use <code>beer.db</code> & <code>world.db</code> in Ruby</li>
<li>How to use HTTP JSON API - <code>GET /beer/guinness</code></li>
<li>Design - Plain text format options</li>
<li>Design - Better comma separated values (CSV) format</li>
<li>Design - "Magic" - Use folder and file names for values and structure</li>
<li>Design - "Magic" - Use text patterns (regex) for fields</li>
</ul>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>What's <code>beer.db</code>?</h1>
<p>A free open public domain beer database & schema
for use in any (programming) language</p>
<p>(e.g. uses plain text fixtures/data sets)</p>
<pre><code>### Brewery
guinness, St. James's Gate Brewery / Guinness Brewery, 1759, D, city:dublin
</code></pre>
<pre><code>### Beer
Guinness|Guinness Draught, 4.2%, by:guinness, irish_dry_stout|dry_stout|stout
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Example: Breweries - <code>breweries.txt</code></h1>
<pre><code>##############################
# Wien
ottakringer, Ottakringer Brauerei, 1838, W, city:wien, »
« 1160 Wien // Ottakringer Straße 91
###########################
# Niederösterreich
zwettler, Zwettler Brauerei, 1709, NÖ, city:zwettl, »
« 3910 Zwettl // Syrnauer Straße 22-25
weitra, Weitra Bräu Bierwerkstatt, 1321, NÖ, city:weitra, »
« 3970 Weitra // Sparkasseplatz 160, zwettler
</code></pre>
<p>Source: <a href="https://github.com/geraldb/beer.db/blob/master/europe/at/breweries.txt"><code>europe/at/breweries.txt</code></a></p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Example: Beers - <code>beers.txt</code></h1>
<pre><code>Ottakringer Helles, 5.2 %, 11.8°, by:ottakringer
Ottakringer Gold Fassl Spezial, 5.6 %, 12.7°, by:ottakringer
Ottakringer (Gold Fassl) Pur, 5.2 %, 11.8°, by:ottakringer, bio
Ottakringer (Gold Fassl) Pils, 4.6 %, 11.2°, by:ottakringer
Ottakringer (Gold Fassl) Zwickl, 5.2 %, 12.2°, by:ottakringer
Zwettler Original, 5.1 %, 11.9°, by:zwettler
Zwettler Pils, 4.9 %, 11.5°, by:zwettler
Zwettler Zwickl, 5.5 %, 12.5°, by:zwettler
Zwettler Dunkles, 3.4 %, 11.5°, by:zwettler
Weitra Helles, 5.0 %, 11.8°, by:weitra
Hadmar, 5.2 %, 12.5°, by:weitra, bio
</code></pre>
<p>Source: <a href="https://github.com/geraldb/beer.db/blob/master/europe/at/beers.txt"><code>europe/at/beers.txt</code></a></p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>How to use <code>beer.db</code> in Ruby</h1>
<p>Brewery Model</p>
<pre><code>by = Brewery.find_by_key( 'guinness' )
by.title
=> 'St. James's Gate Brewery / Guinness Brewery'
by.country.key
=> 'ie'
by.country.title
=> 'Irland'
by.city.title
=> 'Dublin'
by.beers.first
=> 'Guinness', 4.2
...
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>How to use <code>beer.db</code> in Ruby (Cont.)</h1>
<p>Beer Model</p>
<pre><code>b = Beer.find_by_key( 'guinness' )
b.title
=> 'Guinness'
b.abv
=> 4.2
b.tags
=> 'irish_dry_stout', 'dry_stout', 'stout'
b.brewery.title
=> 'St. James's Gate Brewery / Guinness Brewery'
...
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>What's <code>world.db</code>?</h1>
<p>A free open public domain world database & schema
for use in any (programming) language</p>
<p>(e.g. uses plain text fixtures/data sets)</p>
<pre><code>### Countries
at, Austria, AUT, 83_871 km², 8_414_638, un|eu|euro|schengen|central_europe|western_europe
</code></pre>
<pre><code>### Regions (States/Länder/Provinces)
w, Wien [Vienna], 415 km², eastern austria
</code></pre>
<pre><code>### Cities
Wien [Vienna], W, 1_731_236, m:1_724_000
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>How to use <code>beer.db</code> & <code>world.db</code> in Ruby</h1>
<p>Country Model</p>
<pre><code>at = Country.find_by_key( 'at' )
at.title
=> 'Austria'
at.regions.count
=> 9
at.beers
=> 'Weitra Helles', 'Hadmar', 'Zwettler Original', ...
at.breweries
=> 'Weitra Bräu Bierwerkstatt', 'Zwettler Brauerei', ...
...
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>How to use <code>beer.db</code> & <code>world.db</code> in Ruby (Cont.)</h1>
<p>City Model</p>
<pre><code>wien = City.find_by_key( 'wien' )
wien.title
=> 'Wien'
wien.beers
=> 'Ottakringer Helles', 'Ottakringer (Gold Fassl) Zwickl', ...
wien.breweries
=> 'Ottakringer Brauerei'
...
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>How to use HTTP JSON API - <code>GET /beer/guinness</code></h1>
<p>Get beer by key <code>/beer/:key</code></p>
<pre><code>GET /beer/guinness
{
"beer":
{
"key":"guinness",
"title":"Guinness",
"synonyms": "Guinness Draught",
"abv":"4.2",
"srm":null,
"og":null,
"tags":["irish_dry_stout","dry_stout","stout"],
"brewery":
{
"key": "guinness",
"title": "St. James's Gate Brewery / Guinness Brewery"
},
"country":
{
"key":"ie",
"title":"Irland"
}
}
}
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>How to use HTTP JSON API (Cont.) - <code>GET /brewery/guinness</code></h1>
<p>Get brewery by key <code>/brewery/:key</code></p>
<pre><code>GET /brewery/guinness
{
"brewery":
{
"key": "guinness",
"title": "St. James's Gate Brewery / Guinness Brewery",
"synonyms": null,
"since": 1759,
"address": "St. James's Gate // Dublin",
"tags": ["diageo"],
"beers":
[
{
"key": "guinness",
"title": "Guinness"
}
],
"country":
{
"key": "ie",
"title": "Irland"
}
}
}
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Design - Plain text format options</h1>
<ul>
<li>CSV (Comma Separated Values)</li>
<li>TSV (Tab Separated Values)</li>
<li>JSON (JavaScript Object Notation)</li>
<li>XML (eXtensible Markup Language)</li>
<li>YML (Yet Another Markup Language)</li>
<li>SQL (Structured Query Language)</li>
</ul>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Design - Better comma separated values (CSV) format</h1>
<p>What's great with CSV?</p>
<ul>
<li>Simple plain text</li>
<li>One line, one record</li>
</ul>
<p>What's wrong with CSV?</p>
<ul>
<li>No comments</li>
<li>Escaping rules for quotes and commas ugly and not really simple</li>
<li>No optional fields</li>
<li>Fixed order of fields</li>
<li>No "magic" e.g.
<ul>
<li>No auto key generation from title field if leading key field missing (e.g. Guinness => <code>guinness</code>)</li>
<li>No autofill field values from folder names or file names
<ul>
<li>e.g. <code>europe/at</code> sets continent to <code>europe</code> and country to <code>at</code></li>
<li>e.g. <code>beers.2.txt</code> sets type/class to <code>beer</code> and grade to <code>2</code></li>
</ul></li>
</ul></li>
</ul>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Design -"Magic" - Use folder and file names for values and structure</h1>
<p>Do <strong>NOT</strong> put everything into a single file e.g. <code>beers.csv</code>. Better use folders
and use folder and file names for adding some "magic" e.g. to autofill values
e.g. set values for continent, country, city, district, etc. Example:</p>
<p><code>beer.db</code>:</p>
<pre><code>europe/
at/
beers.txt
beers.2.txt
breweries.txt
breweries.2.txt
...
north-america/
mx/
beers.txt
breweries.txt
...
pacific/
au/
...
...
</code></pre>
<p>or</p>
<p><code>wien.db</code>:</p>
<pre><code>1-innere-stadt/
brewpubs.txt
cafes.txt
cinemas.txt
2-leopoldstadt/
...
3-landstraße/
...
</code></pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Design - "Magic" - Use text patterns (regex) for fields</h1>
<h3>Year brewery established</h3>
<p>e.g. 1759 or 1321</p>
<p>Always four digits => <code>/[0-9]{4}/</code></p>
<h3>Region (e.g. state/bundesland/etc.)</h3>
<p>e.g. TX => Texas, or N => Niederösterreich</p>
<p>Always one or two uppercase letters => <code>/[A-Z]{1,2}/</code></p>
<h3>Alcohol by volume (ABV)</h3>
<p>e.g. 5.4% => 5.4</p>
<p>Numbers ending with precent (%) => <code>/[0-9]+(\.[0-9]+)?%/</code></p>
<p>And many more text patterns in use.</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>That's it. Thank you.</h1>
<h3>Links</h3>
<ul>
<li><a href="https://github.com/geraldb/beer.db">github.com/geraldb/beer.db</a></li>
<li><a href="https://github.com/geraldb/football.db">github.com/geraldb/football.db</a></li>
<li><a href="https://github.com/geraldb/world.db">github.com/geraldb/world.db</a></li>
</ul>
<h3>Questions? Comments?</h3>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Bonus: Using CSV, JSON, YML 'n' friends</h1>
<p>Use the HTTP API service and export your data in your format of choice.</p>
<!-- === end markdown block ===================================================== -->
</div>
</div> <!-- presentation -->
</body>
</html>