1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>JSDoc: Source: lib/model/Channel.js</title>
|
6 |
|
7 | <script src="scripts/prettify/prettify.js"> </script>
|
8 | <script src="scripts/prettify/lang-css.js"> </script>
|
9 | |
10 |
|
11 |
|
12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
14 | </head>
|
15 |
|
16 | <body>
|
17 |
|
18 | <div id="main">
|
19 |
|
20 | <h1 class="page-title">Source: lib/model/Channel.js</h1>
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | <section>
|
28 | <article>
|
29 | <pre class="prettyprint source linenums"><code>
|
30 | var util = require('../util');
|
31 |
|
32 | /**
|
33 | * A Stream object
|
34 | * @constructor
|
35 | * @augments Container
|
36 | * @param {Object} obj An object with the Stream properties
|
37 | */
|
38 | var Channel = function (data, stream) {
|
39 |
|
40 | this.dataTypes = require("../data-types");
|
41 |
|
42 | this.data = {
|
43 | unit: null,
|
44 | name: null,
|
45 | type: null,
|
46 | };
|
47 |
|
48 | this.setStream(stream);
|
49 | this.exportProperties();
|
50 | if(data) this.parseJSON(data);
|
51 | };
|
52 | util.extends(Channel, 'Container');
|
53 |
|
54 | Channel.prototype.setStream = function (stream) {
|
55 | this.stream = stream;
|
56 | if(stream.getServiceObject)
|
57 | this.setServiceObject(stream.getServiceObject());
|
58 | };
|
59 |
|
60 | /**
|
61 | * @inheritdoc
|
62 | */
|
63 | Channel.prototype.parseJSON = function (data) {
|
64 |
|
65 | if(typeof data === 'string') {
|
66 | data = {
|
67 | type: data
|
68 | };
|
69 | }
|
70 |
|
71 | if(data.name)
|
72 | this.data.name = data.name;
|
73 |
|
74 | if(data.unit)
|
75 | this.data.unit = data.unit;
|
76 |
|
77 | if(data.type)
|
78 | this.data.type = data.type;
|
79 |
|
80 | this.validate();
|
81 | };
|
82 | /**
|
83 | * @inheritdoc
|
84 | */
|
85 | Channel.prototype.toJSON = function () {
|
86 |
|
87 | var json = this.__super__.toJSON.call(this);
|
88 |
|
89 | if(!json.unit)
|
90 | return json.type;
|
91 |
|
92 | return json;
|
93 | };
|
94 | /**
|
95 | * @inheritdoc
|
96 | */
|
97 | Channel.prototype.validate = function () {
|
98 |
|
99 | if(!this.data.name)
|
100 | throw new Error("Channel name is required");
|
101 |
|
102 | if(!this.data.type)
|
103 | throw new Error("Channel type is required");
|
104 |
|
105 | if(!this.dataTypes.exists(this.data.type))
|
106 | throw new Error("Channel type `"+ this.data.type +"` not supported");
|
107 |
|
108 | };
|
109 |
|
110 | module.exports = Channel;
|
111 | </code></pre>
|
112 | </article>
|
113 | </section>
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | </div>
|
119 |
|
120 | <nav>
|
121 | <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Action.html">Action</a></li><li><a href="Channel.html">Channel</a></li><li><a href="Client.html">Client</a></li><li><a href="Raptor.html">Raptor</a></li><li><a href="RecordSet.html">RecordSet</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="ServiceObject.html">ServiceObject</a></li><li><a href="Stream.html">Stream</a></li><li><a href="User.html">User</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Container">Container</a></li></ul>
|
122 | </nav>
|
123 |
|
124 | <br class="clear">
|
125 |
|
126 | <footer>
|
127 | Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.2</a> on Wed Nov 02 2016 11:15:06 GMT+0100 (CET)
|
128 | </footer>
|
129 |
|
130 | <script> prettyPrint(); </script>
|
131 | <script src="scripts/linenumber.js"> </script>
|
132 | </body>
|
133 | </html>
|