diff options
Diffstat (limited to 'src/viewmodel/name.rs')
-rw-r--r-- | src/viewmodel/name.rs | 105 |
1 files changed, 13 insertions, 92 deletions
diff --git a/src/viewmodel/name.rs b/src/viewmodel/name.rs index e0c3a5b..26beaa1 100644 --- a/src/viewmodel/name.rs +++ b/src/viewmodel/name.rs @@ -1,5 +1,3 @@ -use vcard::properties; -use vcard::values::{self, text}; use super::*; use crate::view::name::*; @@ -12,7 +10,7 @@ pub struct Name { pub suffix: String, } -impl VCardPropertyInputObject<properties::Name, NameView> for Name { +impl VCardPropertyInputObject<NameView> for Name { fn new() -> Self { Self { prefix: String::new(), @@ -68,107 +66,30 @@ impl VCardPropertyInputObject<properties::Name, NameView> for Name { self.last_name.is_empty() && self.suffix.is_empty() } - fn to_vcard_property(&self) -> std::result::Result<properties::Name, Error> { - let name_value = values::name_value::NameValue::from_components( - match self.last_name.is_empty() { - true => None, - false => Some( - match text::Component::from_str(&self.last_name) { - Ok(last_name) => last_name, - Err(_) => return Err(Error{ - msg: String::from("Illegal character in last name."), - }), - } - ), - }, - match self.first_name.is_empty() { - true => None, - false => Some( - match text::Component::from_str(&self.first_name) { - Ok(first_name) => first_name, - Err(_) => return Err(Error{ - msg: String::from("Illegal character in first name."), - }), - } - ), - }, - match self.middle_name.is_empty() { - true => None, - false => Some( - match text::Component::from_str(&self.middle_name) { - Ok(middle_name) => middle_name, - Err(_) => return Err(Error{ - msg: String::from("Illegal character in middle name."), - }), - } - ), - }, - match self.prefix.is_empty() { - true => None, - false => Some( - match text::Component::from_str(&self.prefix) { - Ok(prefix) => prefix, - Err(_) => return Err(Error{ - msg: String::from("Illegal character in prefix."), - }), - } - ), - }, - match self.suffix.is_empty() { - true => None, - false => Some( - match text::Component::from_str(&self.suffix) { - Ok(suffix) => suffix, - Err(_) => return Err(Error{ - msg: String::from("Illegal character in suffix."), - }), - } - ), - }, - ); - - Ok(properties::Name::from_name_value(name_value)) - } } impl Name { - pub fn formatted_name(&self) -> Result<properties::FormattedName, Error> { - let mut formatted_name = String::new(); + pub fn generate_fn(&self) -> String { + let full_name = String::new(); - if !self.prefix.is_empty() { - formatted_name.push_str(&self.prefix); - } + full_name.push_str(&self.prefix); if !self.first_name.is_empty() { - formatted_name.push_str(" "); - formatted_name.push_str(&self.first_name); + full_name.push_str(" "); + full_name.push_str(&self.first_name); } if !self.middle_name.is_empty() { - formatted_name.push_str(" "); - formatted_name.push_str(&self.middle_name); + full_name.push_str(" "); + full_name.push_str(&self.middle_name); } if !self.last_name.is_empty() { - formatted_name.push_str(" "); - formatted_name.push_str(&self.last_name); + full_name.push_str(" "); + full_name.push_str(&self.last_name); } if !self.suffix.is_empty() { - formatted_name.push_str(", "); - formatted_name.push_str(&self.suffix); - } - - if formatted_name.is_empty() { - return Err(Error{ - msg: String::from("Primary name field must not be empty for the formatted name field to be generated."), - }); + full_name.push_str(" "); + full_name.push_str(&self.suffix); } - let formatted_name = properties::FormattedName::from_text( - match text::Text::from_string(formatted_name) { - Ok(formatted_name) => formatted_name, - Err(_) => return Err(Error{ - msg: String::from("Illegal character in formatted name.") // If I see this right, this error should never occur. - }), - } - ); - Ok(formatted_name) + full_name } }
\ No newline at end of file |