diff options
author | Joris | 2022-02-12 16:57:19 +0100 |
---|---|---|
committer | Joris | 2022-02-12 16:57:19 +0100 |
commit | 3adf3f9697c4e2beb10e652947046d5fddda2ed4 (patch) | |
tree | 689e704cf4665cc4cd1949c06d4a7b0553d07501 /src/deck.rs | |
parent | a2ba205df12332a360d89991fe508f964d88c73f (diff) |
Say when the next card will be available
Diffstat (limited to 'src/deck.rs')
-rw-r--r-- | src/deck.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/deck.rs b/src/deck.rs index ce20ee9..af322c6 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -3,6 +3,7 @@ use anyhow::{Error, Result}; use std::fmt; use std::fs::File; use std::io::{prelude::*, BufReader}; +use std::path::Path; #[derive(Debug, Clone)] struct ParseError { @@ -22,7 +23,7 @@ impl std::error::Error for ParseError { } } -pub fn read(deck: String) -> Result<Vec<Entry>> { +pub fn read(deck: &String) -> Result<Vec<Entry>> { let file = File::open(deck)?; let reader = BufReader::new(file); let mut entries: Vec<Entry> = Vec::new(); @@ -66,3 +67,15 @@ pub fn read(deck: String) -> Result<Vec<Entry>> { Ok(entries) } + +pub fn pp_from_path(path: &String) -> Option<String> { + Some(capitalize(Path::new(&path).file_name()?.to_str()?)) +} + +fn capitalize(s: &str) -> String { + let mut c = s.chars(); + match c.next() { + None => String::new(), + Some(f) => f.to_uppercase().collect::<String>() + c.as_str(), + } +} |