Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding copyright, readme, and merges from wolfwood's bug fix.

Signed-off-by: Kurtis Rainbolt-Greene <kurtisrainboltgreene@gmail.com>

Since this gem is now a little popular, I figured I should write a
copyright file. Of course, I use MIT, because it's badass.
Also, a readme file, since others are going to want to know more about
this gem in the future. I hope. Added authors, helpers, and
inspirations. Future naming also added. Going to suuuuck.
Added some white space and made the appropriate changes.
Upped the version, thanks to Wolfwood.
  • Loading branch information...
commit f421b7d157910f999a8753f80d5c4dea16004752 1 parent ade02db
Kurtis Rainbolt-Greene authored
View
19 COPYRIGHT
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Kurtis Rainbolt-Greene:
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
39 README.md
@@ -0,0 +1,39 @@
+time-lord
+---------
+The ruby gem `time-lord` gives extra (needed) methods to the ruby `time` class.
+Originally started as gem that gave dwevelopers the `time-ago-in-words` method for the `time` class.
+It evolved into a multi-part boost to the `Time` class.
+
+
+*postscript* This gem was previously called "time-ago-in-words".
+I changed this, obviously.
+
+
+install
+=======
+Before gem version 0.5.0:
+`gem install time-ago-in-words`
+
+After gem version 0.5.0:
+`gem install time-lord`
+
+
+contribute
+==========
+Whatever you're cool with, really.
+
+
+authors
+=======
+* https://github.com/krainboltgreene
+* https://github.com/sirupsen
+
+
+helpers
+=======
+* https://github.com/wolfwood
+* https://github.com/henrikh
+
+credits
+=======
+* The guy who did the Rails version. I'll find out sometime.
View
41 lib/time-ago-in-words.rb
@@ -1,6 +1,7 @@
require 'time'
class Time
+
Second = 1
Minute = Second * 60
Hour = Minute * 60
@@ -18,85 +19,117 @@ class Time
Century = Decade * 10
Millennium = Century * 10
Eon = 1.0/0
+
def ago_in_words
time = self
+
# Find the time difference between the time provided and the current time.
difference = get_time_difference_from time
-
+
+ # Catch less than 1 second differences.
return "just now" if difference < 1
# Find the smallest unit name of the time difference.
name = get_unit_name_from difference
+
# Find the smallest unit amount of the time difference.
amount = get_unit_amount_from difference
+
# Find then number of units for the time difference.
count = get_unit_count_from difference, amount
+
# Determine if unit name needs pluralization.
- unit = name
- unit += "s" if count != 1
+ name += "s" if count > 1
# Print the remaining string.
- "#{count} #{unit} ago"
+ "#{count} #{name} ago"
end
private
+
def get_time_difference_from time
Time.now.to_i - time.to_i
end
+
def get_unit_count_from difference, amount
difference / amount
end
+
def get_unit_name_from difference
case difference
+
when Second...Minute
"second"
+
when Minute...Hour
"minute"
+
when Hour...Day
"hour"
+
when Day...Week
"day"
+
when Week...Month
"week"
+
when Month...Year
"month"
+
when Year..Decade
"year"
+
when Decade...Century
"decade"
+
when Century...Millennium
"century"
+
when Millennium...Eon
"millennium"
+
else
"eon"
end
end
+
def get_unit_amount_from difference
case difference
+
when Second...Minute
Second
+
when Minute...Hour
Minute
+
when Hour...Day
Hour
+
when Day...Week
Day
+
when Week...Month
Week
+
when Month...Year
Month
+
when Year..Decade
Year
+
when Decade...Century
Decade
+
when Century...Millennium
Century
+
when Millennium...Eon
Millennium
+
else
Eon
end
end
+
alias_method :time_ago_in_words, :ago_in_words
end
View
2  lib/time-ago-in-words/version.rb
@@ -1,3 +1,3 @@
module TimeAgoInWords
- VERSION = "0.1.1"
+ VERSION = "0.1.2"
end
Please sign in to comment.
Something went wrong with that request. Please try again.