1'use strict'
2const TrackerBase = require('./tracker-base.js')
3
4class Tracker extends TrackerBase {
5  constructor (name, todo) {
6    super(name)
7    this.workDone = 0
8    this.workTodo = todo || 0
9  }
10
11  completed () {
12    return this.workTodo === 0 ? 0 : this.workDone / this.workTodo
13  }
14
15  addWork (work) {
16    this.workTodo += work
17    this.emit('change', this.name, this.completed(), this)
18  }
19
20  completeWork (work) {
21    this.workDone += work
22    if (this.workDone > this.workTodo) {
23      this.workDone = this.workTodo
24    }
25    this.emit('change', this.name, this.completed(), this)
26  }
27
28  finish () {
29    this.workTodo = this.workDone = 1
30    this.emit('change', this.name, 1, this)
31  }
32}
33
34module.exports = Tracker
35