-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(article): Add read time functionality (#30)
- add read time method - add read time attribute - return read time when get article [Finishes #166789888]
- Loading branch information
Showing
12 changed files
with
135 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
/** | ||
* Read Time class | ||
*/ | ||
class ReadTime { | ||
/** | ||
* | ||
* @param {Integer} seconds | ||
* @returns {String} minutes | ||
*/ | ||
convert(seconds) { | ||
if (seconds > 60) { | ||
return `${Math.ceil(seconds / 60)} min`; | ||
} | ||
return 'Less than a minute'; | ||
} | ||
|
||
/** | ||
* | ||
* @param {String} words | ||
* @returns {Integer} number of words | ||
*/ | ||
wordsLength(words) { | ||
return words.split(' ').length; | ||
} | ||
|
||
/** | ||
* | ||
* @param {String} text | ||
* @returns {Integer} seconds | ||
*/ | ||
read(text) { | ||
const wordPerSecond = 4; | ||
const words = this.wordsLength(text); | ||
const seconds = words / wordPerSecond; | ||
return this.convert(seconds); | ||
} | ||
} | ||
|
||
export default new ReadTime(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exclude_patterns: | ||
- "src/db/" | ||
- "tests/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { expect } from 'chai'; | ||
import readTime from '../src/helpers/readTime'; | ||
|
||
|
||
describe('Read time tests', () => { | ||
it('should return a beautiful read time', () => { | ||
const text = `Since joining Andela’s Bootcamp, | ||
that was the first time to know how to test my codes, | ||
because there are some situations where the software( like a website) | ||
is being broken in production(means when the users are using that product and face the technical bugs). | ||
The way this was a challenge to me is that I had to learn it fast and implement them immediately. | ||
I found how important it is, the way you target every block of code as input and | ||
expect each possible output in order to catch some errors and correct them before the product | ||
is going to get deployed. The main thing I learned from this challenge is that | ||
I have to make sure my codes are bug-free before getting deployed and make sure my tests are covering every | ||
block of codes. How I adapted to this challenge is, I spent a lot of sleepless nights figuring out how | ||
to write my tests, I didn’t know anything about Travis CI and I got several emails that my builds were failing. | ||
The main key is working hard, ask around and do more research to get your work done.\nGit workflow was another challenge I faced. | ||
I tried it before, but I never tried the feature-branch workflow. | ||
I found that workflow was awesome because it helps you manage the project tasks and work them into branches. | ||
The reason it was a challenge is that we had to work in several branches and merge our work into the main branch and sometimes you face some merge conflicts. | ||
I didn’t know how to resolve conflicts, but I tried to make some research about it, ask my colleagues how to resolve them and luckily | ||
I got my work really organized on Github.`; | ||
expect(readTime.read(text)).to.equal('2 min'); | ||
}); | ||
|
||
it('should get a less than a minute read time', () => { | ||
const text = 'This is an amazing project we are working on, Authors Haven'; | ||
expect(readTime.read(text)).to.equal('Less than a minute'); | ||
}); | ||
}); |