Skip to main content

faker_rust/default/
coffee.rs

1//! Coffee generator - generates random coffee blends, origins, varieties, and notes
2
3use crate::base::sample;
4use crate::locale::{fetch_locale_with_context, sample_with_resolve};
5
6/// Generate a random coffee blend name
7pub fn blend_name() -> String {
8    fetch_locale_with_context("coffee.blend_name", "en", Some("coffee"))
9        .map(|v| sample_with_resolve(&v, Some("coffee")))
10        .unwrap_or_else(|| sample(FALLBACK_BLEND_NAMES).to_string())
11}
12
13/// Generate a random coffee country of origin
14pub fn country() -> String {
15    fetch_locale_with_context("coffee.country", "en", Some("coffee"))
16        .map(|v| sample_with_resolve(&v, Some("coffee")))
17        .unwrap_or_else(|| sample(FALLBACK_COUNTRIES).to_string())
18}
19
20/// Generate a random coffee variety
21pub fn variety() -> String {
22    fetch_locale_with_context("coffee.variety", "en", Some("coffee"))
23        .map(|v| sample_with_resolve(&v, Some("coffee")))
24        .unwrap_or_else(|| sample(FALLBACK_VARIETIES).to_string())
25}
26
27/// Generate a random coffee note
28pub fn notes() -> String {
29    fetch_locale_with_context("coffee.notes", "en", Some("coffee"))
30        .map(|v| sample_with_resolve(&v, Some("coffee")))
31        .unwrap_or_else(|| sample(FALLBACK_NOTES).to_string())
32}
33
34// Fallback data
35const FALLBACK_BLEND_NAMES: &[&str] = &["Summer Solstice", "Winter Wonderland", "Midnight Brew"];
36const FALLBACK_COUNTRIES: &[&str] = &["Ethiopia", "Colombia", "Vietnam", "Brazil", "Indonesia"];
37const FALLBACK_VARIETIES: &[&str] = &["Arabica", "Robusta", "Caturra", "Bourbon", "Typica"];
38const FALLBACK_NOTES: &[&str] = &["fruity", "chocolatey", "nutty", "caramel", "acidic"];
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_blend_name() {
46        assert!(!blend_name().is_empty());
47    }
48
49    #[test]
50    fn test_country() {
51        assert!(!country().is_empty());
52    }
53}