#[cfg(feature = "json")]
use serde::Serialize;
use std::collections::HashMap;
#[derive(Debug)]
#[cfg_attr(feature = "json", derive(Serialize))]
pub struct Author {
pub name: String,
pub total_commits: usize,
pub total_curses: usize,
pub curses: HashMap<String, usize>,
}
impl Author {
pub fn new(name: impl Into<String>) -> Self {
Author {
name: name.into(),
curses: HashMap::new(),
total_commits: 0,
total_curses: 0,
}
}
pub fn update_occurrence(&mut self, curse: &str) {
self.curses
.get_mut(curse)
.map(|c| *c += 1)
.unwrap_or_else(|| {
self.curses.insert(curse.into(), 1);
})
}
pub fn is_naughty(&self) -> bool {
!self.curses.is_empty()
}
}