-
Notifications
You must be signed in to change notification settings - Fork 0
/
songs.js
55 lines (41 loc) · 1.03 KB
/
songs.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
var { concat, map, evolve, prop, concat, toString } = require('ramda');
class Song {
constructor(id, name, album, artists) {
Object.assign(this, { id, name, album, artists })
}
toString() {
return `${this.name}(${this.album}) ${this.artists}`
}
}
class Songs {
constructor(songs) {
this.songs = this.parseSongs(songs);
}
add(songs) {
var songs = this.parseSongs(songs);
this.songs = concat(songs)(this.songs);
}
get(selector) {
return this.songs[selector];
}
clear() {
this.songs = [];
}
parseSongs(songs) {
return map(args => new Song(...args))(songs)
}
getMessage() {
// return map(song => '' + song)(this.songs);
return map(toString)(this.songs);
}
getSelection() {
return map( song =>
({
name: song.toString(),
short: song.name,
value: song.id,
})
)(this.songs);
}
}
module.exports = Songs;