diff --git a/src/bibliography/bib_types/article.rs b/src/bibliography/bib_types/article.rs index baf1713..f9f0b83 100644 --- a/src/bibliography/bib_types/article.rs +++ b/src/bibliography/bib_types/article.rs @@ -43,18 +43,11 @@ impl FromHashMap for Article { let date = parse_date(map.get(K_DATE)?)?; let mut article = Self::new(author.clone(), title.clone(), journal.clone(), date); - if let Some(volume) = map.get(K_VOLUME) { - article.volume = Some(volume.clone()); - } - if let Some(number) = map.get(K_NUMBER) { - article.number = Some(number.clone()); - } - if let Some(pages) = map.get(K_PAGES) { - article.pages = Some(pages.clone()); - } - if let Some(url) = map.get(K_URL) { - article.url = Some(url.clone()); - } + article.volume = map.get(K_VOLUME).cloned(); + article.number = map.get(K_NUMBER).cloned(); + article.number = map.get(K_NUMBER).cloned(); + article.pages = map.get(K_PAGES).cloned(); + article.url = map.get(K_URL).cloned(); Some(Box::new(article)) } diff --git a/src/bibliography/bib_types/book.rs b/src/bibliography/bib_types/book.rs index 6927d40..5eb9f4d 100644 --- a/src/bibliography/bib_types/book.rs +++ b/src/bibliography/bib_types/book.rs @@ -44,21 +44,11 @@ impl FromHashMap for Book { let date = parse_date(map.get(K_DATE)?)?; let mut book = Book::new(author.clone(), title.clone(), publisher.clone(), date); - if let Some(volume) = map.get(K_VOLUME) { - book.volume = Some(volume.clone()); - } - if let Some(series) = map.get(K_SERIES) { - book.series = Some(series.clone()); - } - if let Some(address) = map.get(K_ADDRESS) { - book.address = Some(address.clone()); - } - if let Some(edition) = map.get(K_EDITION) { - book.edition = Some(edition.clone()); - } - if let Some(url) = map.get(K_URL) { - book.url = Some(url.clone()); - } + book.volume = map.get(K_VOLUME).cloned(); + book.series = map.get(K_SERIES).cloned(); + book.address = map.get(K_ADDRESS).cloned(); + book.edition = map.get(K_EDITION).cloned(); + book.url = map.get(K_URL).cloned(); Some(Box::new(book)) } diff --git a/src/bibliography/bib_types/booklet.rs b/src/bibliography/bib_types/booklet.rs index 6f979f4..0db547e 100644 --- a/src/bibliography/bib_types/booklet.rs +++ b/src/bibliography/bib_types/booklet.rs @@ -32,18 +32,10 @@ impl FromHashMap for Booklet { let title = map.get(K_TITLE)?; let mut booklet = Booklet::new(title.clone()); - if let Some(author) = map.get(K_AUTHOR) { - booklet.author = Some(author.clone()) - } - if let Some(how_published) = map.get(K_HOW_PUBLISHED) { - booklet.how_published = Some(how_published.clone()); - } - if let Some(address) = map.get(K_ADDRESS) { - booklet.address = Some(address.clone()); - } - if let Some(date) = map.get(K_DATE) { - booklet.date = parse_date(date); - } + booklet.author = map.get(K_AUTHOR).cloned(); + booklet.how_published = map.get(K_HOW_PUBLISHED).cloned(); + booklet.address = map.get(K_ADDRESS).cloned(); + booklet.date = map.get(K_DATE).and_then(|d| parse_date(d)); Some(Box::new(booklet)) } diff --git a/src/bibliography/bib_types/in_book.rs b/src/bibliography/bib_types/in_book.rs index 8970823..1bf2614 100644 --- a/src/bibliography/bib_types/in_book.rs +++ b/src/bibliography/bib_types/in_book.rs @@ -58,18 +58,10 @@ impl FromHashMap for InBook { date, ); - if let Some(volume) = map.get(K_VOLUME) { - in_book.volume = Some(volume.clone()); - } - if let Some(series) = map.get(K_SERIES) { - in_book.series = Some(series.clone()); - } - if let Some(address) = map.get(K_ADDRESS) { - in_book.address = Some(address.clone()); - } - if let Some(edition) = map.get(K_EDITION) { - in_book.edition = Some(edition.clone()) - } + in_book.volume = map.get(K_VOLUME).cloned(); + in_book.series = map.get(K_SERIES).cloned(); + in_book.address = map.get(K_ADDRESS).cloned(); + in_book.edition = map.get(K_EDITION).cloned(); Some(Box::new(in_book)) } diff --git a/src/bibliography/bib_types/in_collection.rs b/src/bibliography/bib_types/in_collection.rs index 9f18500..db3c8ee 100644 --- a/src/bibliography/bib_types/in_collection.rs +++ b/src/bibliography/bib_types/in_collection.rs @@ -48,14 +48,10 @@ impl FromHashMap for InCollection { let date = parse_date(map.get(K_DATE)?)?; let mut in_col = InCollection::new(author.clone(), title.clone(), publisher.clone(), date); - if let Some(editor) = map.get(K_EDITOR) { - in_col.editor = Some(editor.clone()); - } - if let Some(volume) = map.get(K_VOLUME) { - in_col.volume = Some(volume.clone()); - } + in_col.editor = map.get(K_EDITOR).cloned(); + in_col.volume = map.get(K_VOLUME).cloned(); if let Some(series) = map.get(K_SERIES) { - in_col.series = Some(series.clone()); + Some(series.clone()); } if let Some(position) = map.get(K_POSITION) { in_col.position = Some(position.clone()); diff --git a/src/bibliography/bib_types/manual.rs b/src/bibliography/bib_types/manual.rs index 80b5dd3..b923314 100644 --- a/src/bibliography/bib_types/manual.rs +++ b/src/bibliography/bib_types/manual.rs @@ -34,21 +34,11 @@ impl FromHashMap for Manual { let title = map.get(K_TITLE)?; let mut manual = Manual::new(title.clone()); - if let Some(author) = map.get(K_AUTHOR) { - manual.author = Some(author.clone()); - } - if let Some(org) = map.get(K_ORGANIZATION) { - manual.organization = Some(org.clone()); - } - if let Some(address) = map.get(K_ADDRESS) { - manual.address = Some(address.clone()); - } - if let Some(edition) = map.get(K_EDITION).and_then(|s| Some(s.clone())) { - Some(edition.clone()); - } - if let Some(date) = map.get(K_DATE) { - manual.date = parse_date(date); - } + manual.author = map.get(K_AUTHOR).cloned(); + manual.organization = map.get(K_ORGANIZATION).cloned(); + manual.address = map.get(K_ADDRESS).cloned(); + manual.edition = map.get(K_EDITION).cloned(); + manual.date = map.get(K_DATE).and_then(|d| parse_date(d)); Some(Box::new(manual)) } diff --git a/src/bibliography/bib_types/misc.rs b/src/bibliography/bib_types/misc.rs index 46bd764..53768b9 100644 --- a/src/bibliography/bib_types/misc.rs +++ b/src/bibliography/bib_types/misc.rs @@ -31,21 +31,11 @@ impl FromHashMap for Misc { fn from_hash_map(map: &HashMap) -> Option> { let mut misc = Misc::new(); - if let Some(author) = map.get(K_AUTHOR) { - misc.author = Some(author.clone()) - } - if let Some(title) = map.get(K_TITLE) { - misc.title = Some(title.clone()) - } - if let Some(url) = map.get(K_URL) { - misc.url = Some(url.clone()) - } - if let Some(how_pub) = map.get(K_HOW_PUBLISHED) { - misc.how_published = Some(how_pub.clone()); - } - if let Some(date) = map.get(K_DATE) { - misc.date = parse_date(date); - } + misc.author = map.get(K_AUTHOR).cloned(); + misc.title = map.get(K_TITLE).cloned(); + misc.url = map.get(K_URL).cloned(); + misc.how_published = map.get(K_HOW_PUBLISHED).cloned(); + misc.date = map.get(K_DATE).and_then(|d| parse_date(d)); Some(Box::new(misc)) }