aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/serverLib/StatsManager.js
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2019-03-19 07:36:21 +0100
committermarzavec <admin@marzavec.com>2019-03-19 07:36:21 +0100
commitc634e03cb553e21158fddc6d4221a54aa799de79 (patch)
tree74f303d4ab65b08c7ec316fb713146cc99024c00 /server/src/serverLib/StatsManager.js
parentMerge pull request #56 from paulgreg/manifest (diff)
downloadhackchat-c634e03cb553e21158fddc6d4221a54aa799de79.tar.gz
hackchat-c634e03cb553e21158fddc6d4221a54aa799de79.zip
refactoring 1 of 2
Diffstat (limited to 'server/src/serverLib/StatsManager.js')
-rw-r--r--server/src/serverLib/StatsManager.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/server/src/serverLib/StatsManager.js b/server/src/serverLib/StatsManager.js
new file mode 100644
index 0000000..4ec7ddf
--- /dev/null
+++ b/server/src/serverLib/StatsManager.js
@@ -0,0 +1,59 @@
+/**
+ * Simple generic stats collection script for events occurances (etc)
+ *
+ * Version: v2.0.0
+ * Developer: Marzavec ( https://github.com/marzavec )
+ * License: WTFPL ( http://www.wtfpl.net/txt/copying/ )
+ *
+ */
+
+class StatsManager {
+ /**
+ * Create a stats instance.
+ *
+ */
+ constructor () {
+ this.data = {};
+ }
+
+ /**
+ * Retrieve value of arbitrary `key` reference
+ *
+ * @param {String} key Reference to the arbitrary store name
+ */
+ get (key) {
+ return this.data[key];
+ }
+
+ /**
+ * Set value of arbitrary `key` reference
+ *
+ * @param {String} key Reference to the arbitrary store name
+ * @param {Number} value New value for `key`
+ */
+ set (key, value) {
+ this.data[key] = value;
+ }
+
+ /**
+ * Increase value of arbitrary `key` reference, by 1 or `amount`
+ *
+ * @param {String} key Reference to the arbitrary store name
+ * @param {Number} amount Value to increase `key` by, or 1 if omitted
+ */
+ increment (key, amount) {
+ this.set(key, (this.get(key) || 0) + (amount || 1));
+ }
+
+ /**
+ * Reduce value of arbitrary `key` reference, by 1 or `amount`
+ *
+ * @param {String} key Reference to the arbitrary store name
+ * @param {Number} amount Value to decrease `key` by, or 1 if omitted
+ */
+ decrement (key, amount) {
+ this.set(key, (this.get(key) || 0) - (amount || 1));
+ }
+}
+
+module.exports = StatsManager;