Skip to content

Commit

Permalink
Merge pull request #17 from CarolineMorton/add-metadata
Browse files Browse the repository at this point in the history
add remove author
  • Loading branch information
em-baggie authored Dec 20, 2024
2 parents 1b3d02f + 34259fa commit 8a8ebc9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/src/codelist_validator/bindings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
49 changes: 49 additions & 0 deletions rust/codelist-rs/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ impl Metadata {
}
}

/// Remove an author from the metadata
///
/// # Arguments
/// * `author` - The author to remove
pub fn remove_author(&mut self, author: String) {
if let Some(authors) = &mut self.authors {
let index = authors.iter().position(|x| x == &author);
if let Some(index) = index {
authors.remove(index);
}
}
}

/// Add a description to the metadata
///
/// # Arguments
Expand All @@ -79,6 +92,14 @@ impl Metadata {
self.description = Some(description);
}

/// Remove the description from the metadata
///
/// # Arguments
/// * `description` - The description to remove
pub fn remove_description(&mut self) {
self.description = None;
}

}


Expand Down Expand Up @@ -152,6 +173,19 @@ mod tests {
assert_eq!(metadata.authors, Some(vec!["Author 1".to_string(), "Author 2".to_string()]));
}

#[test]
fn test_remove_author() {
let mut metadata = Metadata {
source: MetadataSource::LoadedFromFile,
authors: Some(vec!["Author 1".to_string(), "Author 2".to_string()]),
version: Some("1.0.0".to_string()),
description: Some("This is a codelist".to_string()),
};

metadata.remove_author("Author 2".to_string());
assert_eq!(metadata.authors, Some(vec!["Author 1".to_string()]));
}

#[test]
fn test_add_description() {
let mut metadata = Metadata {
Expand All @@ -165,4 +199,19 @@ mod tests {
assert_eq!(metadata.description, Some("This is a new description".to_string()));
}

#[test]
fn test_remove_description() {
let mut metadata = Metadata {
source: MetadataSource::LoadedFromFile,
authors: Some(vec!["Author 1".to_string()]),
version: Some("1.0.0".to_string()),
description: Some("This is a codelist".to_string()),
};

metadata.remove_description();
assert_eq!(metadata.description, None);
}



}

0 comments on commit 8a8ebc9

Please sign in to comment.