-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPCategory.ts
76 lines (73 loc) · 1.79 KB
/
MPCategory.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { MPDataField } from "../../index";
/**
* A category which contains a number of fields
*
* @export
* @class MPCategory
* @typedef {MPCategory}
*/
export default class MPCategory {
/**
* Creates an instance of MPCategory.
*
* @constructor
* @private
* @param {string} key The ID of the category.
* @param {string} value The category's readable name.
* @param {?Map<string, MPDataField>} [fields] The category's data fields.
*/
private constructor(
public readonly key: string,
public readonly value: string,
public readonly fields?: Map<string, MPDataField>
) { }
/**
* Creator for MPCategory, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {MPCategoryParams} object
* @returns {MPCategory}
*/
public static create(object: MPCategoryParams): MPCategory {
let fields: Map<string, MPDataField> | undefined;
if (object?.fields !== undefined) {
fields = new Map();
Object.keys(object?.fields).forEach(key => {
fields!.set(key, MPDataField.create(object?.fields!.get(key)))
});
}
return new MPCategory(
object?.key,
object?.value,
fields,
);
}
}
/**
* Parameter interface for {@link MPCategory}.
*
* @export
* @interface MPCategoryParams
* @typedef {MPCategoryParams}
*/
export interface MPCategoryParams {
/**
* The ID of the category.
*
* @type {string}
*/
key: string,
/**
* The category's readable name.
*
* @type {string}
*/
value: string,
/**
* The category's data fields.
*
* @type {?Map<string, MPDataField>}
*/
fields?: Map<string, MPDataField>,
}