Skip to content

Commit bfb55d7

Browse files
authored
Rename assets to children in Resource, close #69 (#167)
1 parent 3e698b8 commit bfb55d7

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Default options you can find in [lib/config/defaults.js](https://github.com/s0ph
6767
- `result`: if error - `null`, if success - array of [Resource](https://github.com/s0ph1e/node-website-scraper/blob/master/lib/resource.js) objects containing:
6868
- `url`: url of loaded page
6969
- `filename`: filename where page was saved (relative to `directory`)
70-
- `assets`: array of children Resources
70+
- `children`: array of children Resources
7171

7272
### Filename Generators
7373
The filename generator determines where the scraped files are saved.

lib/resource.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ function Resource (url, filename) {
44
this.url = url;
55
this.filename = filename;
66

7-
this.assets = [];
87
this.type = null;
98
this.depth = 0;
9+
1010
this.parent = null;
11+
this.children = [];
12+
1113
this.saved = false;
1214
}
1315

@@ -18,15 +20,15 @@ Resource.prototype.createChild = function createChild (url, filename) {
1820
child.parent = this;
1921
child.depth = ++currentDepth;
2022

21-
this.assets.push(child);
23+
this.children.push(child);
2224

2325
return child;
2426
};
2527

2628
Resource.prototype.updateChild = function updateChild (oldChild, newChild) {
27-
var index = this.assets.indexOf(oldChild);
29+
var index = this.children.indexOf(oldChild);
2830
if (index >= 0) {
29-
this.assets[index] = newChild;
31+
this.children[index] = newChild;
3032
}
3133
};
3234

test/functional/base/base.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ describe('Functional base', function() {
7070
result.should.be.instanceOf(Array).and.have.length(3);
7171

7272
result[0].should.have.properties({ url: 'http://example.com/', filename: 'index.html' });
73-
result[0].should.have.properties('assets');
74-
result[0].assets.should.be.instanceOf(Array).and.have.length(4);
75-
result[0].assets[0].should.be.instanceOf(Resource);
73+
result[0].should.have.properties('children');
74+
result[0].children.should.be.instanceOf(Array).and.have.length(4);
75+
result[0].children[0].should.be.instanceOf(Resource);
7676

7777
result[1].should.have.properties({ url: 'http://example.com/about', filename: 'about.html' });
78-
result[1].should.have.properties('assets');
79-
result[1].assets.should.be.instanceOf(Array).and.have.length(4);
80-
result[1].assets[0].should.be.instanceOf(Resource);
78+
result[1].should.have.properties('children');
79+
result[1].children.should.be.instanceOf(Array).and.have.length(4);
80+
result[1].children[0].should.be.instanceOf(Resource);
8181

8282
result[2].should.have.properties({ url: 'http://blog.example.com/', filename: 'blog.html' }); // url after redirect
83-
result[2].should.have.properties('assets');
84-
result[2].assets.should.be.instanceOf(Array).and.have.length(1);
85-
result[2].assets[0].should.be.instanceOf(Resource);
83+
result[2].should.have.properties('children');
84+
result[2].children.should.be.instanceOf(Array).and.have.length(1);
85+
result[2].children[0].should.be.instanceOf(Resource);
8686

8787
// should create directory and subdirectories
8888
fs.existsSync(testDirname).should.be.eql(true);

test/unit/scraper-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('Scraper', function () {
139139
}).catch(done);
140140
});
141141

142-
it('should return array of objects with url, filename and assets', function(done) {
142+
it('should return array of objects with url, filename and children', function(done) {
143143
nock('http://first-url.com').get('/').reply(200, 'OK');
144144
nock('http://second-url.com').get('/').reply(500);
145145

@@ -154,8 +154,8 @@ describe('Scraper', function () {
154154
s.load().then(function(res) {
155155
res.should.be.instanceOf(Array);
156156
res.should.have.length(2);
157-
res[0].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'assets']);
158-
res[1].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'assets']);
157+
res[0].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'children']);
158+
res[1].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'children']);
159159
done();
160160
}).catch(done);
161161
});

0 commit comments

Comments
 (0)