faker_rust/default/
compass.rs1use crate::base::sample;
4use crate::locale::{fetch_locale, sample_with_resolve};
5
6pub fn direction() -> String {
8 fetch_locale("compass.direction", "en")
9 .map(|v| sample_with_resolve(&v, Some("compass")))
10 .unwrap_or_else(|| "north".to_string())
11}
12
13pub fn abbreviation() -> String {
15 fetch_locale("compass.abbreviation", "en")
16 .map(|v| sample_with_resolve(&v, Some("compass")))
17 .unwrap_or_else(|| "N".to_string())
18}
19
20pub fn azimuth() -> String {
22 fetch_locale("compass.azimuth", "en")
23 .map(|v| sample_with_resolve(&v, Some("compass")))
24 .unwrap_or_else(|| "0".to_string())
25}
26
27pub fn cardinal() -> String {
29 fetch_locale("compass.cardinal.word", "en")
30 .map(|v| sample(&v))
31 .unwrap_or_else(|| "north".to_string())
32}
33
34pub fn ordinal() -> String {
36 fetch_locale("compass.ordinal.word", "en")
37 .map(|v| sample(&v))
38 .unwrap_or_else(|| "northeast".to_string())
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_direction() {
47 let d = direction();
48 assert!(!d.is_empty());
49 }
50}