ContentLine.ts 1.33 KB
Newer Older
Mark Stenglein's avatar
Mark Stenglein committed
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { isAlpha } from "./util";

/**
 * Implementation of a Content Line from RFC 5545
 *
 * @author Mark Stenglein <mark@stengle.in>
 *
 * Chapter 3.1 defines the content line. This implementation will use it as an
 * abstract class which can be extended later by the specific content types.
 *
 * This class defines all of the general features specified by the chapter,
 * while leaving the specific features required by individual component objects
 * unfilled.
 */
export class ContentLine {
    private _name: string;
    private _param: string;
    private _value: string;

    constructor(inName: string, inParam: string, inValue: string) {
        this.name = inName;
        this.param = inParam;
        this.value = inValue;
    }

    /* Getters */

    get name(): string {
        return this._name;
    }

    get param(): string {
        return this._param;
    }

    get value(): string {
        return this._value;
    }

    /* Setters */

    set name(newName: string) {
        if (isAlpha(newName)) {
            this._name = newName;
        }
        else {
            throw new TypeError("'name' must be alphabetic!")
        }
    }

    set param(newParam: string) {
        this._param = newParam;
    }

    set value(newValue: string) {
        if (isAlpha(newValue)) {
            this._value = newValue;
        }
    }
}