-
Notifications
You must be signed in to change notification settings - Fork 1
/
waters.cljc
194 lines (144 loc) · 5.76 KB
/
waters.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
(ns common-beer-format.waters
"The definition of a water 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]))
(def water
"A map representing the water used during the mash and for top-up."
:water)
(def waters
"A vector of water records."
:waters)
(def name
"The name of the water record."
:name)
(def version
"The version of the BeerXML specification used to create the water record."
:version)
(def amount
"The amount of water in liters."
:amount)
(def calcium
"The amount of calcium in parts per million."
:calcium)
(def bicarbonate
"The amount of bicarbonate in parts per million."
:bicarbonate)
(def sulfate
"The amount of sulfate in parts per million."
:sulfate)
(def chloride
"The amount of chloride in parts per million."
:chloride)
(def sodium
"The amount of sodium in parts per million."
:sodium)
(def magnesium
"The amount of magnesium in parts per million."
:magnesium)
(def ph
"The pH of the water."
:ph)
(def notes
"Notes about the water profile."
:notes)
(def display-amount
"The amount of water in a human-readable format."
:display-amount)
(spec/def ::calcium
(st/spec
{:type :double
:spec ::prim/non-negative-number
impl/beer-xml-type-key impl/beer-xml-floating-point
:gen impl/real-positive-double-generator
:description "A positive IEEE-754 floating point number representing the amount of calcium (Ca) in parts per million."
:json-schema/example 2.5}))
(spec/def ::bicarbonate
(st/spec
{:type :double
:spec ::prim/non-negative-number
impl/beer-xml-type-key impl/beer-xml-floating-point
:gen impl/real-positive-double-generator
:description "A positive IEEE-754 floating point number representing the amount of bicarbonate (HCO3) in parts per million."
:json-schema/example 2.5}))
(spec/def ::sulfate
(st/spec
{:type :double
:spec ::prim/non-negative-number
impl/beer-xml-type-key impl/beer-xml-floating-point
:gen impl/real-positive-double-generator
:description "A positive IEEE-754 floating point number representing the amount of sulfate (SO4) in parts per million."
:json-schema/example 2.5}))
(spec/def ::chloride
(st/spec
{:type :double
:spec ::prim/non-negative-number
impl/beer-xml-type-key impl/beer-xml-floating-point
:gen impl/real-positive-double-generator
:description "A positive IEEE-754 floating point number representing the amount of chloride (Cl-) in parts per million."
:json-schema/example 2.5}))
(spec/def ::sodium
(st/spec
{:type :double
:spec ::prim/non-negative-number
impl/beer-xml-type-key impl/beer-xml-floating-point
:gen impl/real-positive-double-generator
:description "A positive IEEE-754 floating point number representing the amount of sodium (Na) in parts per million."
:json-schema/example 2.5}))
(spec/def ::magnesium
(st/spec
{:type :double
:spec ::prim/non-negative-number
impl/beer-xml-type-key impl/beer-xml-floating-point
:gen impl/real-positive-double-generator
:description "A positive IEEE-754 floating point number representing the amount of magnesium (Mg) in parts per million."
:json-schema/example 2.5}))
(spec/def ::ph
(st/spec
{:type :double
:spec ::prim/non-negative-number
impl/display-name-key "PH"
impl/beer-xml-type-key impl/beer-xml-floating-point
:gen impl/real-positive-double-generator
:description "A positive IEEE-754 floating point number representing the PH of the water."
:json-schema/example 2.5}))
(spec/def ::water
(st/spec
{:type :map
:description "A record representing the water in a beer recipe."
:spec (spec/keys :req-un [::prim/name
::prim/version
::prim/amount
::calcium
::bicarbonate
::sulfate
::chloride
::sodium
::magnesium]
:opt-un [::ph
::prim/notes
::prim/display-amount])}))
(spec/def ::water-wrapper
(st/spec
{:type :map
impl/wrapper-spec-key true
impl/beer-xml-type-key impl/beer-xml-record
:description "A `::water` record wrapped in a `:water` map."
:spec (spec/keys :req-un [::water])}))
(spec/def ::waters
(st/spec
{:type :vector
:description "A vector of valid `::water` records."
:spec (spec/coll-of ::water-wrapper :into [] :kind vector?)
:decode/string #(impl/decode-sequence %1 ::water-wrapper %2)
:encode/string #(impl/encode-sequence %1 ::water-wrapper %2)}))
(spec/def ::waters-wrapper
(st/spec
{:type :map
impl/wrapper-spec-key true
impl/beer-xml-type-key impl/beer-xml-record-set
:description "A `::waters-wrapper` record set."
:spec (spec/keys :req-un [::waters])}))