Skip to content

Commit

Permalink
Initial Character Model (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-keibler authored Apr 6, 2024
1 parent add85e2 commit f182d50
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 7 deletions.
81 changes: 81 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
members = [
"cypher_character_model"
]

resolver = "2"
6 changes: 4 additions & 2 deletions cypher_character_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name = "cypher_character_model"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.193", features = ["derive"] }

[dev-dependencies]
eyre = "0.6.12"
69 changes: 64 additions & 5 deletions cypher_character_model/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,73 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
use std::fmt::Display;

use serde::{Deserialize, Serialize};

/// Character is the entry-point to the data model
#[derive(Debug, Deserialize, Serialize)]
pub struct Character {
/// The name of the character
pub name: String,
/// The pronouns of the character
pub pronouns: String,
/// The Cypher System sentence that describes the character
pub sentence: Sentence,
}

impl Display for Character {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{} ({}) is a {}",
self.name, self.pronouns, self.sentence
)
}
}

/// Sentence is the high-level description of the character
#[derive(Debug, Deserialize, Serialize)]
pub struct Sentence {
pub descriptor: String,
pub character_type: String,
pub flavor: Option<String>,
pub focus: String,
}

impl Display for Sentence {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let flavor_display = self
.flavor
.as_ref()
.map(|f| format!(" ({f})"))
.unwrap_or_default();
write!(
f,
"{} {}{} who {}",
self.descriptor, self.character_type, flavor_display, self.focus
)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
fn a_charachter_should_display_as_the_sentence() -> eyre::Result<()> {
let character = Character {
name: r#"Lt. Commander Jane "JJ" Jones"#.to_string(),
pronouns: "she/her".to_string(),
sentence: Sentence {
descriptor: "Impulsive".to_string(),
character_type: "Explorer".to_string(),
flavor: Some("Combat".to_string()),
focus: "Sailed Beneath The Jolly Roger".to_string(),
},
};
let actual = character.to_string();
let expected = r#"Lt. Commander Jane "JJ" Jones (she/her) is a Impulsive Explorer (Combat) who Sailed Beneath The Jolly Roger"#;

assert_eq!(actual, expected);

Ok(())
}
}

0 comments on commit f182d50

Please sign in to comment.