Shuo/lib/models/network.js

29 lines
557 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-06-29 01:07:38 +00:00
id: id++,
2014-06-26 23:05:47 +00:00
connected: false,
host: "",
2014-06-29 19:41:02 +00:00
irc: null,
name: capitalize(attr.host.split(".")[1]) || attr.host,
2014-06-26 23:05:47 +00:00
channels: []
}, 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-06-26 23:05:47 +00:00
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}