summaryrefslogtreecommitdiff
path: root/client/js/models/post_metric.js
blob: dd06957a94532befe46d8def8cc065a9981ea66a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';

const events = require('../events.js');

class PostMetric extends events.EventTarget {
    constructor() {
        super();
        this._updateFromResponse({});
    }

    static create(postId, tag) {
        const metric = new PostMetric();
        metric._postId = postId;
        metric._tagName = tag.names[0];
        metric._value = tag.metric.min;
        return metric;
    }

    static fromResponse(response) {
        const metric = new PostMetric();
        metric._updateFromResponse(response);
        return metric;
    }

    get tagName()    { return this._tagName; }
    get postId()     { return this._postId; }
    get value()      { return this._value; }

    set value(value) { this._value = value; }

    _updateFromResponse(response) {
        this._version      = response.version;
        this._postId       = response.post_id;
        this._tagName      = response.tag_name;
        this._value        = response.value;
    }
}

module.exports = PostMetric;