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