-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathabv.rs
30 lines (25 loc) · 1.07 KB
/
abv.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
use rustybeer::calculators::abv::{calculate_abv, calculate_fg};
use rustybeer::conversions::{RelativeDensity, RelativeDensityParser};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "abv", author = "Heikki Hellgren ([email protected])")]
/// Calculates Alcohol By Volume (ABV) from original and final gravity or final gravity from original gravity and ABV
pub struct AbvOptions {
#[structopt(short, long, parse(try_from_str = RelativeDensityParser::parse))]
/// Original gravity
og: RelativeDensity,
#[structopt(short, long, required_unless("abv"), parse(try_from_str = RelativeDensityParser::parse))]
/// Final gravity
fg: Option<RelativeDensity>,
#[structopt(short, long, required_unless("fg"))]
/// Alcohol by volume
abv: Option<f64>,
}
pub fn calculate_and_print(abv_options: AbvOptions) {
if let Some(fg) = abv_options.fg {
println!("ABV: {:.3}%", calculate_abv(&abv_options.og, &fg));
}
if let Some(abv) = abv_options.abv {
println!("ABV: {:.3}%", calculate_fg(&abv_options.og, abv));
}
}