-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
pub use rustybeer_util::hops::{Criteria, Hop, HOPS}; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
#[structopt(name = "hops", author = "Heikki Hellgren ([email protected])")] | ||
/// Finds matches of hops based on parameters | ||
pub struct HopOptions { | ||
#[structopt(short, long)] | ||
/// Alpha acid | ||
alpha_acid: Option<f64>, | ||
|
||
#[structopt(short, long)] | ||
/// Beta acid | ||
beta_acid: Option<f64>, | ||
|
||
#[structopt(short, long)] | ||
/// Hop purpose | ||
purpose: Option<String>, | ||
|
||
#[structopt(short, long)] | ||
/// Substitution of the hop | ||
substituted: Option<String>, | ||
} | ||
|
||
pub fn calculate_and_print(hop_options: HopOptions) { | ||
let criteria = Criteria { | ||
alpha_acid: hop_options.alpha_acid, | ||
beta_acid: hop_options.beta_acid, | ||
purpose: hop_options.purpose, | ||
substituted: hop_options.substituted, | ||
}; | ||
let mut resp: Vec<&Hop> = Vec::new(); | ||
|
||
for hop in HOPS.iter() { | ||
if criteria.matches(hop) { | ||
resp.push(hop) | ||
} | ||
} | ||
|
||
if resp.is_empty() { | ||
println!("Could not find any hops matching criteria"); | ||
return; | ||
} | ||
|
||
println!("Found the following hops with criteria:"); | ||
for x in &resp { | ||
println!("---------------------"); | ||
println!("{}\n", x.name); | ||
println!("{}", x.description); | ||
println!("Country: {}", x.country); | ||
println!("Purpose: {}\n", x.purpose.join(", ")); | ||
println!("Alpha acids: {}-{}", x.alpha_acid_min, x.alpha_acid_max); | ||
println!("Beta acids: {}-{}", x.beta_acid_min, x.beta_acid_max); | ||
println!("Substitutions: {}", x.substitutions.join(", ")); | ||
} | ||
println!("---------------------"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters