-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.cljc
148 lines (124 loc) · 7.26 KB
/
core.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
(ns common-beer-data.core
"Quick functions and references to ingredient data."
{:added "1.0"}
(:require [common-beer-data.fermentables.adjuncts :as adjuncts]
[common-beer-data.fermentables.dry-extracts :as dry-extracts]
[common-beer-data.fermentables.extracts :as extracts]
[common-beer-data.fermentables.grains :as grains]
[common-beer-data.fermentables.sugars :as sugars]
[common-beer-data.hops.aroma :as aroma]
[common-beer-data.hops.bittering :as bittering]
[common-beer-data.hops.both :as both]
[common-beer-data.options :as opts]
[common-beer-data.styles.bjcp-2015.bjcp-2015 :as bjcp-2015]
[common-beer-data.yeasts.brewtek :as brewtek]
[common-beer-data.yeasts.dcl-fermentis :as dcl-fermentis]
[common-beer-data.yeasts.lallemand :as lallemand]
[common-beer-data.yeasts.white-labs :as white-labs]
[common-beer-data.yeasts.wyeast :as wyeast]))
(defn select-fermentables
"Returns a map from keywords to `common-beer-format.fermentables/fermentable` maps based on their attributes.
Legal selection keys include:
- `include-adjuncts?` : Whether or not to include adjuncts in the selection. Adjuncts are non-malted grain starches.
- `include-dry-extracts?` : Whether or not to include dry extracts in the selection. Dry extracts are concentrated extracts of malted grain.
- `include-extracts?` : Whether or not to include extracts in the selection. Extracts are liquid extracts of malted grain.
- `include-grains?` : Whether or not to include malted grains in the selection.
- `include-sugars?` : Whether or not to include pure sugars or sugar syrups in the selection."
{:added "1.0"}
[{:keys [include-adjuncts? include-dry-extracts? include-extracts? include-grains? include-sugars?]}]
(cond-> {}
include-adjuncts? (merge adjuncts/adjuncts)
include-dry-extracts? (merge dry-extracts/dry-extracts)
include-extracts? (merge extracts/extracts)
include-grains? (merge grains/grains)
include-sugars? (merge sugars/sugars)))
(def all-fermentables
"A map from keywords to `common-beer-format.fermentables/fermentable` maps for all fermentables.
This is a convenience function for `select-fermentables` with all options set to true."
(select-fermentables {opts/include-adjuncts? true
opts/include-dry-extracts? true
opts/include-extracts? true
opts/include-grains? true
opts/include-sugars? true}))
(defn get-fermentable
"Returns the `common-beer-format.hops/hop` at the given keyword.
If the keyword is not found, returns nil a la `clojure.core/get`.
An optional last entry may be used to specify a default value to return if the keyword is not found."
{:added "1.0"}
([fermentable-key]
(get all-fermentables fermentable-key))
([fermentable-key default-value]
(get all-fermentables fermentable-key default-value)))
(defn select-hops
"Returns a map from keywords to `common-beer-format.hops/hop` maps based on their attributes.
Legal selection keys include:
- `include-aroma?` : Whether or not to include aromatic hops in the selection. Aromatic hops are hops with a low bitterness, or typically added for their essential oils.
- `include-bittering?` : Whether or not to include bittering hops in the selection. Bittering hops are typically added for their strong, musky flavor.
- `include-both?` : Whether or not to include hops which can be used for both aroma and bittering in the selection."
{:added "1.0"}
[{:keys [include-aroma? include-bittering? include-both?]}]
(cond-> {}
include-aroma? (merge aroma/aroma)
include-bittering? (merge bittering/bittering)
include-both? (merge both/both)))
(def all-hops
"A map from keywords to `common-beer-format.hops/hop` maps for all hops.
This is a convenience function for `select-hops` with all options set to true."
(select-hops {opts/include-aroma? true
opts/include-bittering? true
opts/include-both? true}))
(defn get-hop
"Returns the `common-beer-format.hops/hop` at the given keyword.
If the keyword is not found, returns nil a la `clojure.core/get`.
An optional last entry may be used to specify a default value to return if the keyword is not found."
{:added "1.0"}
([hop-key]
(get all-hops hop-key))
([hop-key default-value]
(get all-hops hop-key default-value)))
(defn select-style-guides
"Returns a map from keywords to `common-beer-format.stlyes/style` maps based on their attributes.
Legal selection keys include:
- `include-bjcp-2015?` : Whether or not to include the [BJCP 2015](https://www.bjcp.org/bjcp-style-guidelines/) style guide in the selection."
{:added "1.0"}
[{:keys [include-bjcp-2015?]}]
(cond-> {}
include-bjcp-2015? (merge bjcp-2015/all-styles)))
(def all-style-guides
"A map from keywords to `common-beer-format.stlyes/style` maps for all style guides.
This is a convenience function for `select-style-guides` with all options set to true."
(select-style-guides {opts/include-bjcp-2015? true}))
(defn select-yeasts
"Returns a map from keywords to `common-beer-format.yeasts/yeast` maps based on their attributes.
Legal selection keys include:
- `include-brewtek?` : Whether or not to include yeasts manufactured by BrewTek in the selection.
- `include-dcl-fermentis?` : Whether or not to include yeasts manufactured by [Fermentis](https://fermentis.com/en/) in the selection.
- `include-lallemand?` : Whether or not to include yeasts manufactured by [Lallemand](https://www.lallemand.com/) in the selection.
- `include-white-labs?` : Whether or not to include yeasts manufactured by [White Labs](https://www.whitelabs.com/) in the selection.
- `include-wyeast?` : Whether or not to include yeasts manufactured by [Wyeast](https://www.wyeastlab.com/) in the selection."
{:added "1.0"}
[{:keys [include-brewtek? include-dcl-fermentis? include-lallemand? include-white-labs? include-wyeast?]}]
(cond-> {}
include-brewtek? (merge brewtek/brewtek)
include-dcl-fermentis? (merge dcl-fermentis/dcl-fermentis)
include-lallemand? (merge lallemand/lallemand)
include-white-labs? (merge white-labs/white-labs)
include-wyeast? (merge wyeast/wyeast)))
(def all-yeasts
"A map from keywords to `common-beer-format.yeasts/yeast` maps for all yeasts.
This is a convenience function for `select-yeasts` with all options set to true."
(select-yeasts {opts/include-brewtek? true
opts/include-dcl-fermentis? true
opts/include-lallemand? true
opts/include-white-labs? true
opts/include-wyeast? true}))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn get-yeast
"Returns the `common-beer-format.yeasts/yeast` at the given keyword.
If the keyword is not found, returns nil a la `clojure.core/get`.
An optional last entry may be used to specify a default value to return if the keyword is not found."
{:added "1.0"}
([yeast-key]
(get all-yeasts yeast-key))
([yeast-key default-value]
(get all-yeasts yeast-key default-value)))