git_anger_management/
author.rs1use serde::Serialize;
2use std::collections::HashMap;
3
4#[derive(Debug, Serialize)]
6pub struct Author {
7 pub name: String,
9 pub total_commits: usize,
11 pub total_curses: usize,
13 pub curses: HashMap<String, usize>,
15}
16
17impl Author {
18 pub fn new(name: impl Into<String>) -> Self {
20 Author {
21 name: name.into(),
22 curses: HashMap::new(),
23 total_commits: 0,
24 total_curses: 0,
25 }
26 }
27
28 pub fn update_occurrence(&mut self, curse: &str) {
30 self.curses
31 .get_mut(curse)
32 .map(|c| *c += 1)
33 .unwrap_or_else(|| {
34 self.curses.insert(curse.into(), 1);
35 })
36 }
37
38 pub fn is_naughty(&self) -> bool {
40 !self.curses.is_empty()
41 }
42}