2014-06-26 23:05:47 +00:00
|
|
|
var _ = require("lodash");
|
2014-06-29 19:41:02 +00:00
|
|
|
var Chan = require("./chan");
|
2014-06-26 23:05:47 +00:00
|
|
|
|
|
|
|
module.exports = Network;
|
|
|
|
|
2014-06-29 01:07:38 +00:00
|
|
|
var id = 0;
|
|
|
|
|
2014-06-26 23:05:47 +00:00
|
|
|
function Network(attr) {
|
|
|
|
_.merge(this, _.extend({
|
2014-07-08 20:50:41 +00:00
|
|
|
channels: [],
|
2014-06-26 23:05:47 +00:00
|
|
|
connected: false,
|
|
|
|
host: "",
|
2014-07-08 20:50:41 +00:00
|
|
|
id: id++,
|
2014-06-29 19:41:02 +00:00
|
|
|
irc: null,
|
2014-07-08 20:50:41 +00:00
|
|
|
name: prettify(attr.host)
|
2014-06-26 23:05:47 +00:00
|
|
|
}, attr));
|
2014-06-29 19:41:02 +00:00
|
|
|
this.channels.unshift(
|
|
|
|
new Chan({name: this.name, type: Chan.Type.LOBBY})
|
|
|
|
);
|
2014-06-26 23:05:47 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 19:41:02 +00:00
|
|
|
Network.prototype.toJSON = function() {
|
|
|
|
return _.omit(this, "irc");
|
|
|
|
};
|
|
|
|
|
2014-07-08 20:50:41 +00:00
|
|
|
function prettify(host) {
|
|
|
|
var name = capitalize(host.split(".")[1]);
|
|
|
|
if (!name) {
|
|
|
|
name = host;
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2014-06-26 23:05:47 +00:00
|
|
|
function capitalize(str) {
|
2014-08-25 10:14:28 +00:00
|
|
|
if (typeof str === "string") {
|
|
|
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
|
|
}
|
2014-06-26 23:05:47 +00:00
|
|
|
}
|