UNPKG

3.38 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>JSDoc: Source: lib/model/ResultSet.js</title>
6
7 <script src="scripts/prettify/prettify.js"> </script>
8 <script src="scripts/prettify/lang-css.js"> </script>
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
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/ResultSet.js</h1>
21
22
23
24
25
26
27 <section>
28 <article>
29 <pre class="prettyprint source linenums"><code>
30var _ = require('lodash');
31
32var RecordSet = require('./RecordSet');
33var util = require('../util');
34
35/**
36 * An object containing a collection of RecordSet
37 * @constructor
38 * @param {Array} data A list of values
39 * @returns {ResultSet} An object containing the data
40 */
41var ResultSet = function (data, stream) {
42 this.data = [];
43 this.setStream(stream);
44 if(data) this.fromJSON(data);
45};
46util.extends(ResultSet, 'Container');
47
48/**
49 * @inheritdoc
50 */
51ResultSet.prototype.fromJSON = function (data) {
52 var me = this;
53 _.forEach(data, function(rawRecord) {
54 me.data.push(new RecordSet(rawRecord, me.getStream()));
55 });
56 this.validate();
57};
58
59/**
60 * @inheritdoc
61 */
62ResultSet.prototype.toJSON = function () {
63 return this.data.map(function(r) {
64 return r.toJSON();
65 });
66};
67
68/**
69 * @inheritdoc
70 */
71ResultSet.prototype.validate = function () {
72 _.forEach(this.data, function(record) {
73 record.validate();
74 });
75};
76
77/**
78 * Set a stream reference
79 * @param {Stream} stream a stream object reference
80 */
81ResultSet.prototype.setStream = function (s) {
82 this.stream = s;
83 if(s &amp;&amp; s.getServiceObject) {
84 this.setServiceObject(s.getServiceObject());
85 }
86};
87
88/**
89 * Get a stream reference
90 * @return {Stream} stream the stream object reference
91 */
92ResultSet.prototype.stream = ResultSet.prototype.getStream = function () {
93 return this.stream;
94};
95
96/**
97 * Return a RecordSet at the specified index if available
98 * @param {Number} idx Index position
99 * @return {RecordSet} record record object
100 */
101ResultSet.prototype.get = function (idx) {
102 return this.data[idx] || null;
103};
104
105/**
106 * Return the count of available records
107 * @return {Number} length count of records
108 */
109ResultSet.prototype.size = function () {
110 return this.data.length;
111};
112
113
114module.exports = ResultSet;
115</code></pre>
116 </article>
117 </section>
118
119
120
121
122</div>
123
124<nav>
125 <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>
126</nav>
127
128<br class="clear">
129
130<footer>
131 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)
132</footer>
133
134<script> prettyPrint(); </script>
135<script src="scripts/linenumber.js"> </script>
136</body>
137</html>