diff options
author | Akshay <[email protected]> | 2020-02-27 12:53:19 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-02-27 12:53:19 +0000 |
commit | cc8cde9b229b1cd8de8e9e67b164c80b1cdc0ebf (patch) | |
tree | 438de2cdd2edb48f62951175ae3d90602fe9ff8b /src | |
parent | 16a01454c2340c8f631f17277647737aeb5e3049 (diff) |
add helpers for statusline
Diffstat (limited to 'src')
-rw-r--r-- | src/habit.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/habit.rs b/src/habit.rs index 8527ac2..7d50adf 100644 --- a/src/habit.rs +++ b/src/habit.rs | |||
@@ -34,6 +34,7 @@ pub trait HabitTrait { | |||
34 | fn insert_entry(&mut self, date: NaiveDate, val: HabitType); | 34 | fn insert_entry(&mut self, date: NaiveDate, val: HabitType); |
35 | fn reached_goal(&self, date: NaiveDate) -> bool; | 35 | fn reached_goal(&self, date: NaiveDate) -> bool; |
36 | fn remaining(&self, date: NaiveDate) -> u32; | 36 | fn remaining(&self, date: NaiveDate) -> u32; |
37 | fn total(&self) -> u32; | ||
37 | } | 38 | } |
38 | 39 | ||
39 | #[derive(Serialize, Debug)] | 40 | #[derive(Serialize, Debug)] |
@@ -75,7 +76,7 @@ impl Habit { | |||
75 | } else { | 76 | } else { |
76 | match self.goal { | 77 | match self.goal { |
77 | HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(true)), | 78 | HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(true)), |
78 | HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)), | 79 | HabitType::Count(_) => self.insert_entry(date, HabitType::Count(1)), |
79 | } | 80 | } |
80 | } | 81 | } |
81 | } | 82 | } |
@@ -119,7 +120,13 @@ impl HabitTrait for Habit { | |||
119 | HabitType::Count(c) => return self.goal.inner_count() - *c, | 120 | HabitType::Count(c) => return self.goal.inner_count() - *c, |
120 | } | 121 | } |
121 | } else { | 122 | } else { |
122 | return 0; | 123 | return self.total(); |
124 | } | ||
125 | } | ||
126 | fn total(&self) -> u32 { | ||
127 | match self.goal { | ||
128 | HabitType::Bit(_) => return 1, | ||
129 | HabitType::Count(c) => return c, | ||
123 | } | 130 | } |
124 | } | 131 | } |
125 | } | 132 | } |