Project

elapser

0.0
No commit activity in last 3 years
No release in over 3 years
When creating apps, you might find it handy to see how long ago was something created. For example, if you are builing a simple ToDo application, you might want to display how long ago did a particular todo was added to the list
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.7
~> 10.0
>= 0
 Project Readme

Elapser

Gem that provides time between now and when something was created using the column created_at that is added when using timestamps macro in an Active Record migration

Installation

Add this line to your application's Gemfile:

gem 'elapser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install elapser

Usage

Add elapser to your gemfile

gem 'elapser', '~> 1.0.1'

Require elapser

require 'elapser'
  1. Use it!!!
   Elapser.time_calc("2015-02-13 00:36:46 UTC")
   #=> 9 weeks ago 
   #Consider this example was posted 2015-04-13

Note: If you are using created_at from active record, make sure you call to_s, for example:

    Elapser.time_calc(todo.created_at.to_s)
   # todo is just the name of my model it could be anything

Example using ERB

    #@note is equal to all notes in my db (@note=Note.all)
    #@note is passed as an instance variable in our get route
    
    <% @note.reverse.each do |note| %>
      <ul>
        <li> Created by: <%= note.user.user_name if note.user != nil %></li>
        <li> <%= note.description %></li>
        <li>Posted <%= Elapser.time_calc(note.created_at.to_s)%></li>
      </ul>
     <%end%>
# DISPLAY ON THE BROWSER
* Created by: andres
* hello again
* Posted 8 weeks ago

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Acknowledgements

I created this gem as an educational exercise to learn the process and inner workings for creating a gem. I also believe it could be useful to other fellow rubyst. I want to thank instructor Sherif Abushadi and peer Richard Santin who contributed and without them this project would have not existed.