also display 'parts_of_speech'

This commit is contained in:
jojii 2021-02-18 17:59:11 +01:00
parent e298065a5d
commit 59cc62f5c8

View file

@ -83,22 +83,51 @@ fn print_item(query: &str, value: &Value) -> Option<()> {
fn format_sense(value: &Value, index: usize) -> String { fn format_sense(value: &Value, index: usize) -> String {
let english_definitons = value.get("english_definitions"); let english_definitons = value.get("english_definitions");
let parts_of_speech = value.get("parts_of_speech");
if english_definitons.is_none() { if english_definitons.is_none() {
return "".to_owned(); return "".to_owned();
} }
let english_definiton = value_to_arr(english_definitons.unwrap()); let english_definiton = value_to_arr(english_definitons.unwrap());
let parts_of_speech = if parts_of_speech.is_some() {
let parts = value_to_arr(parts_of_speech.unwrap())
.to_owned()
.iter()
.map(|i| {
let s = value_to_str(i);
match s {
"Suru verb - irregular" => "Irregular verb",
"Ichidan verb" => "iru/eru verb",
_ => {
if s.contains("Godan verb") {
"Godan verb"
} else {
s
}
}
}
})
.collect::<Vec<&str>>()
.join(", ");
format!("[{}]", parts.bright_blue())
} else {
String::new()
};
let tags = format_sense_tags(value); let tags = format_sense_tags(value);
format!( format!(
"{}. {} {}", "{}. {} {} {}",
index + 1, index + 1,
english_definiton english_definiton
.iter() .iter()
.map(|i| value_to_str(i)) .map(|i| value_to_str(i))
.collect::<Vec<&str>>() .collect::<Vec<&str>>()
.join(", "), .join(", "),
tags tags,
parts_of_speech
) )
} }