Skip to content

Commit

Permalink
refactor: make quote's src non none-able
Browse files Browse the repository at this point in the history
  • Loading branch information
dmyTRUEk committed Mar 29, 2024
1 parent 8faa37a commit 82bb1dd
Show file tree
Hide file tree
Showing 4 changed files with 694 additions and 698 deletions.
11 changes: 5 additions & 6 deletions generate_quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def main():
output.append("")
else:
if quote is None:
quote = Quote(text=line, char="", src=None, whom_to=None, whom_about=None)
quote = Quote(text=line, char="", src="", whom_to=None, whom_about=None)
elif quote.char == "":
quote.char = name_to_identifier(line)
elif quote.char != "" and quote.src is None:
elif quote.char != "" and quote.src == "":
quote.src = line
elif line.startswith("whom_to: "):
whom_to = line[9:]
Expand Down Expand Up @@ -72,7 +72,7 @@ def main():
class Quote:
text: str
char: str
src: None | str
src: str
whom_to: None | str
whom_about: None | str

Expand All @@ -81,16 +81,15 @@ def to_lines(self) -> list[str]:
"\tQuote {",
f"\t\ttext: \"{self.text}\",",
f"\t\tchar: {self.char},",
f"\t\tsrc: \"{self.src}\",",
]
if self.src is not None:
lines.append(f"\t\tsrc: Some(\"{self.src}\"),")
if self.whom_to is not None:
whom_to = name_to_identifier(self.whom_to)
lines.append(f"\t\twhom_to: Some({whom_to}),")
if self.whom_about is not None:
whom_about = name_to_identifier(self.whom_about)
lines.append(f"\t\twhom_about: Some({whom_about}),")
if self.src is None or self.whom_about is None or self.whom_to is None:
if self.whom_about is None or self.whom_to is None:
lines.append("\t\t..Quote::default()")
lines.append("\t},")
return lines
Expand Down
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ fn main() -> Result<(), &'static str> {
let maybe_about = whom_about
.map(|whom_about| format!(" about {}", whom_about.to_str()))
.unwrap_or_default();
let maybe_src = src
.map(|src| format!(", \"{}\"", src))
.unwrap_or_default();
println!("\"{text}\"\n-- {char}{maybe_to}{maybe_about}{maybe_src}");
println!("\"{text}\"\n-- {char}{maybe_to}{maybe_about}, \"{src}\"");
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::characters::Character;
pub struct Quote {
pub text: &'static str,
pub char: Character,
pub src: Option<&'static str>,
pub src: &'static str,
pub whom_to: Option<Character>,
/// `char` says `text` about who?
pub whom_about: Option<Character>,
Expand All @@ -16,7 +16,7 @@ impl Quote {
Self {
text: "default text",
char: Character::Unknown,
src: None,
src: "default src",
whom_to: None,
whom_about: None,
}
Expand Down
Loading

0 comments on commit 82bb1dd

Please sign in to comment.