-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAgency.js
155 lines (146 loc) · 5.03 KB
/
Agency.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*global define, module*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(["./conversionUtils", "./Datafile"], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require("./conversionUtils.js"), require("./Datafile.js"));
} else {
// Browser globals (root is window)
root.Agency = factory(root.conversionUtils, root.Datafile);
}
}(this, function (conversionUtils, Datafile) {
/**
* @module Agency
*/
/** An object representing an agency that publishes GTFS data to GTFS-Exchange.
* @constructor
* @alias module:Agency
* @param {Object} data - Data corresponding to class's properties.
* @param {?Object.<string, object>} datafiles - An array of {@link DataFile} objects.
*/
function Agency(data, datafiles) {
var _dateAdded = null, _dateLastUpdated = null;
Object.defineProperties(this, {
/** @member {string} */
dataexchange_id: {
enumerable: true,
writable: true,
value: null
}, // "abq-ride"
/** @member {string} */
feed_baseurl: {
enumerable: true,
writable: true,
value: null
}, // "http://data.cabq.gov/transit/gtfs/google_transit.zip",
/** @member {string} */
name: {
enumerable: true,
writable: true,
value: null
}, // "ABQ Ride",
/** @member {string} */
area: {
enumerable: true,
writable: true,
value: null
}, // "Albuquerque",
/** @member {string} */
url: {
enumerable: true,
writable: true,
value: null
}, // "http://myabqride.com",
/** @member {string} */
country: {
enumerable: true,
writable: true,
value: null
}, // "United States",
/** @member {string} */
state: {
enumerable: true,
writable: true,
value: null
}, // "New Mexico",
/** @member {string} */
license_url: {
enumerable: true,
writable: true,
value: null
}, // "",
/** @member {string} */
dataexchange_url: {
enumerable: true,
writable: true,
value: null
}, // "http://www.gtfs-data-exchange.com/agency/abq-ride/",
/** @member {Date} */
date_added: {
enumerable: true,
get: function () {
return _dateAdded;
},
set: function (v) {
_dateAdded = conversionUtils.convertDateToDateObject(v); // 1340739867.0,
}
},
/** @member {Date} */
date_last_updated: {
enumerable: true,
get: function () {
return _dateLastUpdated;
},
set: function (v) {
_dateLastUpdated = conversionUtils.convertDateToDateObject(v); // 1340739867.0,
}
},
/** @member {boolean} */
is_official: {
enumerable: true,
writable: true,
value: null
}, // true,
/** @member {DataFile[]} */
datafiles: {
enumerable: true,
writable: true,
value: null
},
/** @member {string} - URL for the most current GTFS ZIP file */
latestFeedUrl: {
get: function () {
this.dataexchange_url ? this.dataexchange_url.replace(/\/$/, "") + "/latest.zip" : null;
}
}
});
if (data && typeof data === "object") {
var name, desc;
for (name in data) {
if (data.hasOwnProperty(name) && this.hasOwnProperty(name)) {
this[name] = data[name];
}
}
}
}
/** Group an array of agencies by area.
* @param {Agency[]} agencies - An array of agencies.
* @returns {Object.<string, Agency[]>} - Arrays of agencies grouped by area.
*/
Agency.groupByArea = function (agencies) {
var grouped = {};
agencies.forEach(function (agency) {
if (!grouped.hasOwnProperty(agency.area)) {
grouped[agency.area] = [agency];
} else {
grouped[agency.area].push(agency);
}
});
return grouped;
};
return Agency;
}));