forked from Ideabile/ood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (52 loc) · 1.92 KB
/
index.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
(function(global){
function Obj(){
var self = this;
self.attributes = arguments[0] || { name: '' };
}
// Person
// This is a generic person to rapresent the participants
function Person(){
Obj.call(this, arguments[0]);
}
function somethingExceptPerson( person ){
return !(person instanceof global.Person);
}
Person.prototype.brings = function(ingredients){
if(!this.attributes.brings) this.attributes.brings = [];
if(typeof ingredients === "object"){
for(var i in ingredients){
this.attributes.brings.push(ingredients[i]);
}
}else{
this.attributes.brings.push(ingredients);
}
};
global.Person = Person;
var Meal = Obj;
Meal.prototype._addPartecipant = function(person){
if(!this.attributes.partecipants) this.attributes.partecipants = [];
if(somethingExceptPerson(person)) throw new Error('You should pass a Person to add a Partecipant');
if(!person.type) person.type = "guest";
this.attributes.partecipants.push(person);
};
Meal.prototype.addGuest = function(person){
if(!this.attributes.guests) this.attributes.guests = [];
if(somethingExceptPerson(person)) throw new Error('You should pass a Person to add a Guest');
person.attributes.type = 'guest';
this._addPartecipant(person);
this.attributes.guests.push(person);
};
Meal.prototype.addOwner = function(owner){
if(!this.attributes.owner) this.attributes.owner = false;
if(somethingExceptPerson(owner)) throw new Error('You should define a Person to set');
owner.attributes.type = 'owner';
this._addPartecipant(owner);
this.attributes.owner = owner;
};
global.Meal = Meal;
global.Ingredient = global.Manipulation = global.Recipe = Obj;
var dinners = require('./src/dinners'),
last_dinner = dinners[(dinners.length-1)],
Utils = require('./src/utils');
Utils.render(last_dinner);
})(global || window);