forked from bitfloor/nacha
-
Notifications
You must be signed in to change notification settings - Fork 1
/
record.js
48 lines (36 loc) · 1021 Bytes
/
record.js
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
// builtin
var assert = require('assert');
var records = require('./records.json');
var Field = require('./field');
var Record = function(fields) {
var Obj = function() {
if (!(this instanceof Obj)) {
return new Obj();
}
var self = this;
self.fields = fields.map(Field);
self.fields.forEach(function(field) {
Object.defineProperty(self, field.name, {
get: function() {
return field.get();
},
set: function(val) {
field.set(val);
}
});
});
};
Obj.prototype.serialize = function() {
var self = this;
var out = '';
self.fields.forEach(function(field) {
out += field.serialize();
});
assert.equal(out.length, 94, 'invalid record length');
return out;
};
return Obj;
}
for (var rec in records) {
module.exports[rec] = Record(records[rec]);
}