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'- Use it!!!
Elapser.time_calc("2015-02-13 00:36:46 UTC")
#=> 9 weeks ago
#Consider this example was posted 2015-04-13Note: 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 anythingExample 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 agoContributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - 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.