ramadhan-cli-rust 0.1.0

Ramadan-first CLI for Sehar and Iftar timings in your terminal
Documentation
use std::collections::{HashMap, HashSet};

fn country_method_map() -> HashMap<&'static str, i64> {
    HashMap::from([
        ("United States", 2),
        ("USA", 2),
        ("US", 2),
        ("Canada", 2),
        ("Mexico", 2),
        ("Pakistan", 1),
        ("Bangladesh", 1),
        ("India", 1),
        ("Afghanistan", 1),
        ("United Kingdom", 3),
        ("UK", 3),
        ("Germany", 3),
        ("Netherlands", 3),
        ("Belgium", 3),
        ("Sweden", 3),
        ("Norway", 3),
        ("Denmark", 3),
        ("Finland", 3),
        ("Austria", 3),
        ("Switzerland", 3),
        ("Poland", 3),
        ("Italy", 3),
        ("Spain", 3),
        ("Greece", 3),
        ("Japan", 3),
        ("China", 3),
        ("South Korea", 3),
        ("Australia", 3),
        ("New Zealand", 3),
        ("South Africa", 3),
        ("Saudi Arabia", 4),
        ("Yemen", 4),
        ("Oman", 4),
        ("Bahrain", 4),
        ("Egypt", 5),
        ("Syria", 5),
        ("Lebanon", 5),
        ("Palestine", 5),
        ("Jordan", 5),
        ("Iraq", 5),
        ("Libya", 5),
        ("Sudan", 5),
        ("Iran", 7),
        ("Kuwait", 9),
        ("Qatar", 10),
        ("Singapore", 11),
        ("France", 12),
        ("Turkey", 13),
        ("Türkiye", 13),
        ("Russia", 14),
        ("United Arab Emirates", 16),
        ("UAE", 16),
        ("Malaysia", 17),
        ("Brunei", 17),
        ("Tunisia", 18),
        ("Algeria", 19),
        ("Indonesia", 20),
        ("Morocco", 21),
        ("Portugal", 22),
    ])
}

fn hanafi_countries() -> HashSet<&'static str> {
    HashSet::from([
        "Pakistan",
        "Bangladesh",
        "India",
        "Afghanistan",
        "Turkey",
        "Türkiye",
        "Iraq",
        "Syria",
        "Jordan",
        "Palestine",
        "Kazakhstan",
        "Uzbekistan",
        "Tajikistan",
        "Turkmenistan",
        "Kyrgyzstan",
    ])
}

pub fn get_recommended_method(country: &str) -> Option<i64> {
    let map = country_method_map();

    if let Some(method) = map.get(country) {
        return Some(*method);
    }

    let normalized = country.to_ascii_lowercase();
    map.into_iter()
        .find(|(key, _)| key.to_ascii_lowercase() == normalized)
        .map(|(_, value)| value)
}

pub fn get_recommended_school(country: &str) -> i64 {
    let direct = hanafi_countries();
    if direct.contains(country) {
        return 1;
    }

    let normalized = country.to_ascii_lowercase();
    if direct
        .iter()
        .any(|entry| entry.to_ascii_lowercase() == normalized)
    {
        return 1;
    }

    0
}

#[cfg(test)]
mod tests {
    use super::{get_recommended_method, get_recommended_school};

    #[test]
    fn method_lookup_is_case_insensitive() {
        assert_eq!(get_recommended_method("Pakistan"), Some(1));
        assert_eq!(get_recommended_method("pakistan"), Some(1));
    }

    #[test]
    fn school_recommendation_matches_expected_defaults() {
        assert_eq!(get_recommended_school("Pakistan"), 1);
        assert_eq!(get_recommended_school("Canada"), 0);
    }
}