-
Notifications
You must be signed in to change notification settings - Fork 0
/
hops.cljc
392 lines (286 loc) · 11.9 KB
/
hops.cljc
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
(ns common-beer-format.hops
"The definition of a hop record used in BeerXML"
{:added "2.0"}
(:require [clojure.spec.alpha :as spec]
[common-beer-format.impl :as impl]
[common-beer-format.primitives :as prim]
[spec-tools.core :as st])
(:refer-clojure :exclude [name type time use]))
(def hop
"A map representing a hop."
:hop)
(def hops
"A vector of hops."
:hops)
(def name
"The name of the hop."
:name)
(def version
"The version of the BeerXML specification used to create the hop record."
:version)
(def alpha
"The percent contents of alpha acid in the hop."
:alpha)
(def amount
"The amount of the hop in the recipe."
:amount)
(def use
"The means by which the hop is added to the beer.
Currently, the following uses are allowed:
- `boil` - Hops added to the boil.
- `dry hop` - Hops added to the fermentation vessel after pitching yeast.
- `mash` - Hops added to the mash prior to the boil.
- `first wort` - Hops added to the first wort.
- `aroma` - Hops added to the beer for aroma."
:use)
(def time
"The time in minutes the hop was added dependant on the `:use` field."
:time)
(def notes
"Notes about the hop."
:notes)
(def type
"The type of hop added to the beer, based on its intended purpose.
Currently, the following types are allowed:
- `bittering` - Hops added solely for their bittering properties.
- `aroma` - Hops added solely for their aromatic properties and flavor.
- `both` - Hops which may be added for both their bittering and aromatic properties."
:type)
(def form
"The form of the hop added to the beer.
Currently, the following forms are allowed:
- `pellet` - Hops in pellet form.
- `plug` - Hops in plug form.
- `leaf` - Hops in leaf form."
:form)
(def beta
"The percent contents of beta acid in the hop."
:beta)
(def hsi
"The Hop Stability Index, or percent decay of a hop's alpha acid over six months."
:hsi)
(def origin
"The origin of the hop."
:origin)
(def substitutes
"A string containing suitable alternative hop names to use as a replcaement for the hop."
:substitutes)
(def humulene
"The percent contents of humulene in the hop, which contributes to the unique aroma of hops."
:humulene)
(def caryophyllene
"The percent contents of caryophyllene in the hop, which contributes to the peppery characteristics of hop aroma."
:caryophyllene)
(def cohumulone
"The percent contents of cohumulone in the hop, which contributes to the sour characteristics of hop aroma."
:cohumulone)
(def myrcene
"The percent contents of myrcene in the hop, which contributes to the earthy characteristics of hop aroma."
:myrcene)
(def display-amount
"The amount of the hop in the recipe, formatted for display."
:display-amount)
(def display-time
"The time in minutes the hop was added dependant on the `:use` field, formatted for display."
:display-time)
(def inventory
"The amount of the hop in inventory."
:inventory)
(spec/def ::alpha
(st/spec
{:type :double
:spec ::prim/percent
impl/beer-xml-type-key impl/beer-xml-percentage
:description "A non-negative IEEE-754 floating point number representing the percent contents of alpha acid in the hop."
:json-schema/example "10.7"}))
(def boil
"Hops added to the boil."
"Boil")
(def dry-hop
"Hops added to the fermentation vessel after pitching yeast."
"Dry Hop")
(def mash
"Hops added to the mash prior to the boil."
"Mash")
(def first-wort
"Hops added to the first wort."
"First Wort")
(def aroma
"Hops added to the beer for aroma."
"Aroma")
(def hop-uses
"The allowed values for the means by which the hop is added to the beer."
#{aroma
boil
dry-hop
first-wort
mash})
(spec/def ::use
(st/spec
{:type :string
:spec hop-uses
impl/beer-xml-type-key impl/beer-xml-list
:gen #(spec/gen hop-uses)
:description (impl/multiline "A case-sensitive string representing the means by which the hop is added to the beer."
(impl/set->description hop-uses)
""
"- Aroma: Hops added to the beer after the boil. They do not significantly contribute to the bitterness of the beer."
"- Boil: Hops added to the boil for bittering."
"- Dry Hop: Hops added to the fermentation vessel after pitching yeast. They do not significantly contribute to the bitterness of the beer."
"- First Wort: Hops added to first wort prior to the boil."
"- Mash: Hops added to the mash prior to the boil.")
:json-schema/example "mash"}))
(spec/def ::time
(st/spec
{:type :double
:spec ::prim/minute
impl/beer-xml-type-key impl/beer-xml-floating-point
impl/beer-xml-units-key impl/beer-xml-minute
:description (impl/multiline
"A non-negative IEEE-754 floating point number representing the time in minutes the hop was added dependant on the `:use` field."
""
"- Boil: this is the boil time."
"- Mash: this is the mash time."
"- First Wort: this is the boil time."
"- Aroma: this is the steep time."
"- Dry Hop: this is the amount of time to dry hop.")
:json-schema/example "15.0"}))
(def bittering
"Hops added to the boil for bittering."
"Bittering")
(def both
"Hops added to the boil for both bittering and aroma."
"Both")
(def hop-types
"The allowed values for the type of hop."
#{bittering
aroma
both})
(spec/def ::type
(st/spec
{:type :string
:spec hop-types
impl/beer-xml-type-key impl/beer-xml-list
:gen #(spec/gen hop-types)
:description (impl/multiline "A case-sensitive string representing the typical purpose of the hop's addition to a beer."
(impl/set->description hop-types)
""
"- Bittering: Hops added solely for their bittering properties."
"- Aroma: Hops added solely for their aromatic properties and flavor."
"- Both: Hops which may be added for both/either their bittering and/or aromatic properties.")
:json-schema/example "bittering"}))
(def pellet
"Hops added to the boil in pellet form."
"Pellet")
(def plug
"Hops added to the boil in plug form."
"Plug")
(def leaf
"Hops added to the boil in whole leaf form."
"Leaf")
(def hop-forms
"The allowed values for the physical form of the hop."
#{pellet
plug
leaf})
(spec/def ::form
(st/spec
{:type :string
:spec hop-forms
impl/beer-xml-type-key impl/beer-xml-list
:gen #(spec/gen hop-forms)
:description (impl/multiline "A case-sensitive string representing the physical form of the hop."
(impl/set->description hop-forms)
""
"- Pellet: Ground and compressed hop cones."
"- Plug: Whole hop cones compressed into plugs."
"- Leaf: Whole hop cones.")
:json-schema/example "leaf"}))
(spec/def ::beta
(st/spec
{:type :double
:spec ::prim/percent
impl/beer-xml-type-key impl/beer-xml-percentage
:description "A non-negative IEEE-754 floating point number representing the percent contents of beta acid in the hop."
:json-schema/example "10.7"}))
(spec/def ::hsi
(st/spec
{:type :double
impl/display-name-key "Hop Stability Index"
impl/beer-xml-type-key impl/beer-xml-percentage
:spec ::prim/percent
:description "A non-negative IEEE-754 floating point number representing the Hop Stability Index, or percent decay of a hop's alpha acid over six months."
:json-schema/example "2.2"}))
(spec/def ::humulene
(st/spec
{:type :double
:spec ::prim/percent
impl/beer-xml-type-key impl/beer-xml-percentage
:description "A non-negative IEEE-754 floating point number representing the percent contents of humulene in the hop."
:json-schema/example "10.7"}))
(spec/def ::caryophyllene
(st/spec
{:type :double
:spec ::prim/percent
impl/beer-xml-type-key impl/beer-xml-percentage
:description "A non-negative IEEE-754 floating point number representing the percent contents of caryophyllene in the hop."
:json-schema/example "10.7"}))
(spec/def ::cohumulone
(st/spec
{:type :double
:spec ::prim/percent
impl/beer-xml-type-key impl/beer-xml-percentage
:description "A non-negative IEEE-754 floating point number representing the percent contents of cohumulone in the hop."
:json-schema/example "10.7"}))
(spec/def ::myrcene
(st/spec
{:type :double
:spec ::prim/percent
impl/beer-xml-type-key impl/beer-xml-percentage
:description "A non-negative IEEE-754 floating point number representing the percent contents of myrcene in the hop."
:json-schema/example "10.7"}))
(spec/def ::hop
(st/spec
{:type :map
:description "A record representing a hop in a beer recipe."
:spec (spec/keys :req-un [::prim/name
::prim/version
::alpha
::prim/amount
::use
::time]
:opt-un [::prim/notes
::type
::form
::beta
::hsi
::prim/origin
::prim/substitutes
::humulene
::caryophyllene
::cohumulone
::myrcene
::prim/display-amount
::prim/inventory
::prim/display-time])}))
(spec/def ::hop-wrapper
(st/spec
{:type :map
impl/wrapper-spec-key true
impl/beer-xml-type-key impl/beer-xml-record
:description "A `::hop` record wrapped in a `:hop` map."
:spec (spec/keys :req-un [::hop])}))
(spec/def ::hops
(st/spec
{:type :vector
:description "A vector of valid `::hop-wrapper` records."
:spec (spec/coll-of ::hop-wrapper :into [] :kind vector?)
:decode/string #(impl/decode-sequence %1 ::hop-wrapper %2)
:encode/string #(impl/encode-sequence %1 ::hop-wrapper %2)}))
(spec/def ::hops-wrapper
(st/spec
{:type :map
impl/wrapper-spec-key true
impl/beer-xml-type-key impl/beer-xml-record-set
:description "A `::hops-wrapper` record set."
:spec (spec/keys :req-un [::hops])}))