hardlounge/lib/models/network.js

37 lines
655 B
JavaScript
Raw Normal View History

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) {
return str.charAt(0).toUpperCase() + str.slice(1);
}