-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
priming.rs
37 lines (32 loc) · 1.41 KB
/
priming.rs
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
use rustybeer::calculators::priming::{calculate_co2, calculate_sugars};
use rustybeer::{
conversions::{TemperatureParser, ToMap, VolumeParser},
measurements::{Temperature, Volume},
};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "priming")]
/// Beer Priming Calculator
pub struct PrimingOptions {
#[structopt(short, long, parse(try_from_str = TemperatureParser::parse))]
/// Temperature of beer with unit (C, F, K). Defaults to Celsius.
temp: Temperature,
#[structopt(short, long = "amount", parse(try_from_str = VolumeParser::parse))]
/// Amount being packaged with unit (l, ml, gal, etc.). Defaults to liters.
amount: Volume,
#[structopt(short, long = "co2_volumes", default_value = "2.0")]
/// Volumes of wanted CO2, depends on beer style (e.g. British Style Ales 1.5 to 2.0)
co2_volumes: f64,
}
pub fn calculate_and_print(priming: PrimingOptions) {
let co2_beer = calculate_co2(&priming.temp);
let sugars = calculate_sugars(&priming.temp, &priming.amount, priming.co2_volumes);
println!("Amount: {:#?}", priming.amount.to_map());
println!("Volumes of CO2: {}", priming.co2_volumes);
println!("Temperature: {:#?}", priming.temp.to_map());
println!("CO2 in Beer: {:.2} volumes", co2_beer);
println!("Priming Sugar Options:");
for sugar in sugars.iter() {
println!("{:>23}: {:#?}", sugar.name, sugar.ratio.to_map());
}
}