Ballasi / num2words

Convert numbers like 42 to forty-two
https://crates.io/crates/num2words
Apache License 2.0
17 stars 9 forks source link

Add a .prefer() function #3

Closed Ballasi closed 2 years ago

Ballasi commented 2 years ago

Something I would like to add for the English language before moving on to other languages is the ability to set preferences.

For instance, here is a sample code:

use num2words::*;

fn print_game_score(home_score: i64, away_score: i64) -> Result<(), Num2Err> {
    println!(
        "{} - {}",
        Num2Words::new(home_score).to_words()?,
        Num2Words::new(away_score).to_words()?
    );
    Ok(())
}

Calling print_game_score(3, 0).unwrap() would print three - zero, but in this case, we are more likely to be interested to see three - nil, same for "oh" (e.g., in versioning).

I am interested in implementing a call similar to the one below:

Num2Words::new(home_score).prefer(["nil"]).to_words()