aboutsummaryrefslogtreecommitdiff
path: root/src/deck.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/deck.rs')
-rw-r--r--src/deck.rs15
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(),
+ }
+}