-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbeer_style.rs
65 lines (55 loc) · 1.89 KB
/
beer_style.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
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
pub use rustybeer::beer_styles::{BeerStyle, Criteria, BEER_STYLES};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "beer_style", author = "Heikki Hellgren ([email protected])")]
/// Finds matches of beer style based on parameters
pub struct BeerStyleOptions {
#[structopt(short, long)]
/// Beer style name
name: Option<String>,
#[structopt(short, long)]
/// Original gravity
og: Option<f32>,
#[structopt(short, long)]
/// Final gravity
fg: Option<f32>,
#[structopt(short, long)]
/// Alcohol by volume
abv: Option<f32>,
#[structopt(short, long)]
/// International Bittering Units
ibu: Option<u8>,
#[structopt(short, long)]
/// Standard Reference Model Color
color: Option<f32>,
}
pub fn calculate_and_print(beer_style_options: BeerStyleOptions) {
let criteria = Criteria {
name: beer_style_options.name,
og: beer_style_options.og,
fg: beer_style_options.fg,
abv: beer_style_options.abv,
ibu: beer_style_options.ibu,
srm: beer_style_options.color,
};
let resp: Vec<&BeerStyle> = BEER_STYLES
.iter()
.filter(|style| criteria.matches(style))
.collect();
if resp.is_empty() {
println!("Could not find any beer styles matching criteria");
return;
}
println!("Found the following beer styles with criteria:");
for x in &resp {
println!("---------------------");
println!("{}\n", x.name);
println!("{}\n", x.description);
println!("OG: {}-{}", x.original_gravity_min, x.original_gravity_max);
println!("FG: {}-{}", x.final_gravity_min, x.final_gravity_max);
println!("ABV: {}%-{}%", x.abv_min, x.abv_max);
println!("IBU: {}-{}", x.ibu_min, x.ibu_max);
println!("SRM: {}-{}", x.color_srm_min, x.color_srm_max);
}
println!("---------------------");
}