Giter Site home page Giter Site logo

readingtime's Introduction

Estimate Reading Time

Build Status Code Climate

I use iA Writer and find the estimated reading time feature pretty handy. I thought it would be cool to add at the top of my blog articles on the web as others do.

How to Use

readingtime extends the Ruby String class, so you can call reading_time on any String object.

Install

gem install readingtime

In irb

$ irb
> require 'readingtime'
=> true
> @words = "Lorem ipsum dolor sit amet"
> @words.reading_time
=> "00:01"

In Your App

<article>

  <header>
    <h1><%= @article.title %></h1>
    <span class="readingtime">Estimated reading time โ€“ <%= @article.body.reading_time %></span>
  </header>

  <%= @article.body %>

</article>

And voila!

Screenshot of readingtime in use

Options

You can also send in options to modify the formatting.

# Default output
@article.body.reading_time :format => :basic
=> "03:36"

# Longer text output
@article.body.reading_time :format => :long
=> "3 minutes and 36 seconds"

# Approximate output to minutes
@article.body.reading_time :format => :approx
=> "4 minutes"

# Full text output
@article.body.reading_time :format => :full
=> "1 hr 3 mins 36 secs"

# Raw output [hours, minutes, seconds]
@article.body.reading_time :format => :raw
=> [1, 12, 23]

Thanks

Credit goes to Brian Cray for explaining how to do it in PHP.

readingtime's People

Contributors

garethrees avatar maxehmookau avatar jenkoian avatar henggana avatar igorkasyanchuk avatar bravosimone avatar walidvb avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.