Skip to content

Commit 408fd75

Browse files
committed
docs: complete overhaul of the docs and the readme file
The previous docs were incomplete and weren't updated to fit the new builder format the crate is using. Changes were needed.
1 parent 06d2bd2 commit 408fd75

File tree

5 files changed

+284
-58
lines changed

5 files changed

+284
-58
lines changed

README.md

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,46 @@
44

55
Convert number like `42` to `forty-two`
66

7+
## Usage
8+
9+
This crate can be either used as a library or a binary.
10+
11+
### Library
12+
713
Example usage:
14+
815
```rust
916
use num2words::Num2Words;
1017
assert_eq!(Num2Words::new(42).to_words(), Ok(String::from("forty-two")));
1118
```
1219

13-
The app can also be run via a command-line interface.
20+
The builder Num2Words can take three arguments: `lang`, `output` and
21+
`currency`.
22+
23+
```rust
24+
use num2words::*;
25+
assert_eq!(
26+
Num2Words::new(42).lang(Lang::English).to_words(),
27+
Ok(String::from("forty-two"))
28+
);
29+
assert_eq!(
30+
Num2Words::new(42).output(Output::Ordinal).to_words(),
31+
Ok(String::from("forty-second"))
32+
);
33+
assert_eq!(
34+
Num2Words::new(42.01).currency(Currency::DOLLAR).to_words(),
35+
Ok(String::from("forty-two dollars and one cent"))
36+
);
37+
```
38+
39+
These arguments can be chained.
40+
41+
For more information about the available languages, outputs and currencies,
42+
see [Informations](#informations).
43+
44+
### Binary
45+
46+
This crate provides a command-line interface to run requests on `num2words`.
1447

1548
Example:
1649
```sh
@@ -25,24 +58,63 @@ You can download the app via the following command:
2558
$ cargo install num2words
2659
```
2760

28-
For more information about the usage of `num2words` please refers to the
29-
docs or via the following command:
61+
You can also change the language via the argument `--lang` and provide an
62+
output or a currency with the argument `--to`.
63+
64+
For more information about the usage of `num2words` please refer to the docs
65+
or via the following command:
3066
```sh
3167
$ num2words --help
3268
```
3369

70+
## Informations
71+
72+
### Supported languages
73+
74+
Here is a list of all of the supported languages:
75+
76+
| Flag | Code | CLI code | Language | 42 |
77+
| ---- | --------------- | --------------- | -------- | --------- |
78+
| 🇺🇸🇬🇧 | `Lang::English` | `en` | English | forty-two |
79+
80+
This list can be expanded! Contributions are welcomed.
81+
82+
### Supported output
83+
84+
Here is a list of all of the supported outputs (with the command-line
85+
interface code):
86+
87+
- `Output::Cardinal` (`cardinal`): forty-two (42)
88+
- `Output::Currency` (any available currencies): forty-two dollars and one
89+
cent (42.01)
90+
- `Output::Ordinal` (`ordinal`): forty-second (42)
91+
- `Output::OrdinalNum` (`ordinal_num`): 42nd (42)
92+
- `Output::Year` (`year`): nineteen oh-one (1901)
93+
94+
### Supported currencies
95+
96+
Here is a list of all of the supported currencies (with the command-line
97+
interface code):
98+
99+
- `Currency::AUD` (`AUD`): australian dollar
100+
- `Currency::CAD` (`CAD`): canadian dollar
101+
- `Currency::DOLLAR` (`DOLLAR`): dollar
102+
- `Currency::EUR` (`EUR`): euro
103+
- `Currency::GBP` (`GBP`): pound
104+
- `Currency::USD` (`USD`): US dollar
105+
106+
### About
107+
34108
This library is widely inspired by [Savoir-faire Linux's Python
35109
lib](https://github.com/savoirfairelinux/num2words/).
36110

37-
**Warning**: this lib is not usable at its current state, we would recommend
38-
you come back later.
39-
40111
## License
41112

42113
Licensed under either of
43114

44115
- Apache License, Version 2.0
45-
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
116+
([LICENSE-APACHE](LICENSE-APACHE) or
117+
http://www.apache.org/licenses/LICENSE-2.0)
46118
- MIT license
47119
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
48120

@@ -51,5 +123,5 @@ at your option.
51123
## Contribution
52124

53125
Unless you explicitly state otherwise, any contribution intentionally submitted
54-
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
55-
dual licensed as above, without any additional terms or conditions.
126+
for inclusion in the work by you, as defined in the Apache-2.0 license,
127+
shall be dual licensed as above, without any additional terms or conditions.

src/lang/lang.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,27 @@ pub trait Language {
1212
fn to_currency(self, num: Number, currency: Currency) -> Result<String, Num2Err>;
1313
}
1414

15+
/// Languages available in `num2words`
1516
pub enum Lang {
17+
/// ```
18+
/// use num2words::{Num2Words, Lang};
19+
/// assert_eq!(
20+
/// Num2Words::new(42).lang(Lang::English).to_words(),
21+
/// Ok(String::from("forty-two"))
22+
/// );
23+
/// ```
1624
English,
1725
}
1826

1927
impl FromStr for Lang {
2028
type Err = ();
2129

30+
/// Parses a string to return a value of this type
31+
///
32+
///
33+
/// | &str | Lang | 42 |
34+
/// | ---- | --------------- | --------- |
35+
/// | `en` | `Lang::English` | forty-two |
2236
fn from_str(input: &str) -> Result<Self, Self::Err> {
2337
match input {
2438
"en" => Ok(Self::English),

src/lib.rs

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,109 @@
44
/*!
55
* Convert number like `42` to `forty-two`
66
*
7+
* ## Usage
8+
*
9+
* This crate can be either used as a library or a binary.
10+
*
11+
* ### Library
12+
*
713
* Example usage:
8-
* ```
14+
*
15+
* ```rust
916
* use num2words::Num2Words;
1017
* assert_eq!(Num2Words::new(42).to_words(), Ok(String::from("forty-two")));
1118
* ```
1219
*
13-
* This lib will also be a downloadable binary in the near future.
20+
* The builder Num2Words can take three arguments: `lang`, `output` and
21+
* `currency`.
22+
*
23+
* ```rust
24+
* use num2words::*;
25+
* assert_eq!(
26+
* Num2Words::new(42).lang(Lang::English).to_words(),
27+
* Ok(String::from("forty-two"))
28+
* );
29+
* assert_eq!(
30+
* Num2Words::new(42).output(Output::Ordinal).to_words(),
31+
* Ok(String::from("forty-second"))
32+
* );
33+
* assert_eq!(
34+
* Num2Words::new(42.01).currency(Currency::DOLLAR).to_words(),
35+
* Ok(String::from("forty-two dollars and one cent"))
36+
* );
37+
* ```
38+
*
39+
* These arguments can be chained.
40+
*
41+
* For more information about the available languages, outputs and currencies,
42+
* see [Informations](#informations).
43+
*
44+
* ### Binary
45+
*
46+
* This crate provides a command-line interface to run requests on `num2words`.
47+
*
48+
* Example:
49+
* ```sh
50+
* $ num2words 42
51+
* forty-two
52+
* $ num2words 10 --to EUR
53+
* ten euros
54+
* ```
55+
*
56+
* You can download the app via the following command:
57+
* ```sh
58+
* $ cargo install num2words
59+
* ```
60+
*
61+
* You can also change the language via the argument `--lang` and provide an
62+
* output or a currency with the argument `--to`.
63+
*
64+
* For more information about the usage of `num2words` please refer to the docs
65+
* or via the following command:
66+
* ```sh
67+
* $ num2words --help
68+
* ```
69+
*
70+
* ## Informations
71+
*
72+
* ### Supported languages
73+
*
74+
* Here is a list of all of the supported languages:
75+
*
76+
* | Flag | Code | CLI code | Language | 42 |
77+
* | ---- | --------------- | --------------- | -------- | --------- |
78+
* | 🇺🇸🇬🇧 | `Lang::English` | `en` | English | forty-two |
79+
*
80+
* This list can be expanded! Contributions are welcomed.
1481
*
15-
* For more detailed usage about the different parameters that you can give
16-
* to the macro, please take a look at [`num2words!`].
82+
* ### Supported output
83+
*
84+
* Here is a list of all of the supported outputs (with the command-line
85+
* interface code):
86+
*
87+
* - `Output::Cardinal` (`cardinal`): forty-two (42)
88+
* - `Output::Currency` (any available currencies): forty-two dollars and one
89+
* cent (42.01)
90+
* - `Output::Ordinal` (`ordinal`): forty-second (42)
91+
* - `Output::OrdinalNum` (`ordinal_num`): 42nd (42)
92+
* - `Output::Year` (`year`): nineteen oh-one (1901)
93+
*
94+
* ### Supported currencies
95+
*
96+
* Here is a list of all of the supported currencies (with the command-line
97+
* interface code):
98+
*
99+
* - `Currency::AUD` (`AUD`): australian dollar
100+
* - `Currency::CAD` (`CAD`): canadian dollar
101+
* - `Currency::DOLLAR` (`DOLLAR`): dollar
102+
* - `Currency::EUR` (`EUR`): euro
103+
* - `Currency::GBP` (`GBP`): pound
104+
* - `Currency::USD` (`USD`): US dollar
105+
*
106+
* ### About
17107
*
18108
* This library is widely inspired by [Savoir-faire Linux's Python
19109
* lib](https://github.com/savoirfairelinux/num2words/).
20-
*
21-
* **Warning**: this lib is not usable at its current state, we would recommend
22-
* you come back later.
23110
*/
24111
mod num2words;
25112
mod currency;

0 commit comments

Comments
 (0)