forked from makersacademy/news-summary-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newsModel.js
45 lines (36 loc) · 892 Bytes
/
newsModel.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
class NewsModel {
constructor() {
this.articles = []
this.keyword = 'undefined'
this.relevantArticles = []
}
addArticles(articles){
this.articles = []
this.articles = []
articles.forEach((article) => {
this.addArticle(article)
})
}
addArticle = (article) => {
const newArticle = {}
newArticle.title = article.webTitle;
newArticle.url = article.webUrl;
newArticle.image = article.fields.thumbnail;
this.articles.push(newArticle)
}
viewArticles(){
return this.articles
}
matchingKeyword = (article) => {
if (article.title.includes(this.keyword)) {
this.relevantArticles.push(article)
}
}
matchingArticles(keyword) {
this.relevantArticles = []
this.keyword = keyword
this.articles.map(this.matchingKeyword)
return this.relevantArticles
}
}
module.exports = NewsModel