Repository is archived
No commit activity in last 3 years
No release in over 3 years
Estimate how many seconds it'll take to read an article
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0
~> 0.44.1

Runtime

 Project Readme

ArticleReadingtime

Given an HTML article, it calculates an estimated reading time for it. Similar to what Medium does, although the exact behavior can be customized.

Installation

Add this line to your application's Gemfile:

gem 'article_readingtime'

And then execute:

$ bundle

Or install it yourself as:

$ gem install article_readingtime

Usage

require 'article_readingtime'

ArticleReadingtime.estimate_html <<HTML
  <article>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididun
    </p>
  </article>
HTML

#=> 3

ArticleReadingtime.estimate_html receives an HTML string and returns an estimate of the time in seconds it takes to read it. By default, it considers an average of 275 WPM. The first image is counted as 12 seconds, the second one as 11 seconds, and it keeps decreasing down to 3 seconds for each image. A second optional parameter can be used to customize these values:

ArticleReadingtime.estimate_html <<HTML, wpm: 300
  <article>
    <!-- ... -->
  </article>
HTML

Image time calculation can be customized by changing the maximum, minimum and step. For instance, for the first image to be counted as 15 seconds, down until 5 seconds, and reduce 2 seconds for each new image, the options would look like:

ArticleReadingtime.estimate_html <<HTML, images: { max: 15, min: 5, step: 2 }
  <article>
    <!-- ... -->
  </article>
HTML

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/julioolvr/article_readingtime.

License

The gem is available as open source under the terms of the MIT License.