time_ago_in_words 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17816bdfb96d3a2e1e9ba53f3dd6e2db69a31682
4
- data.tar.gz: c68a369e2faeb1db7aed0dbe215eb63fbe72d492
3
+ metadata.gz: 3643c74e96a16cf5b7a3052eec2cf8b0041d89c4
4
+ data.tar.gz: b835b4a256c661bfb5133da03e55cbceccdb6b75
5
5
  SHA512:
6
- metadata.gz: 8eac441414aecb182c726f1bf80e7398f642a3c74a461cf78843207abb69ad8878e04e9f0d183703b460e4fdc011ba69a9e7eb6c5d715c368a59ca7722e52ff6
7
- data.tar.gz: e80b0d1598bacb957ac0d493c54a60cd47a974448a2426a516ba1722b312526bd0fa942d463989f2fd8277e7622c052f0671a9295d969a4c29b15875a3eb99c3
6
+ metadata.gz: 434184bf95eed3f42cf0cdaf0c04340c35fb9dbe661cf0296e80f819c5aa4b0d48bf70deeba089e4d3cfc3a2e828d2060d77854d818769973116c647a5542c67
7
+ data.tar.gz: 3cb1145b769db7a50b466c36bf192b47afa12ede96692da37116a2387186306badb6121523e9149fde2e1d884b71ecd43c52238f58ffae5501c4b337e621b4e2
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0.0
@@ -1,4 +1,4 @@
1
- ## [In git](https://github.com/elgalu/time_ago_in_words/compare/v0.0.1...HEAD)
1
+ ## [In git](https://github.com/elgalu/time_ago_in_words/compare/v0.1.0...HEAD)
2
2
 
3
3
  ### New Features
4
4
  * n/a
@@ -9,6 +9,17 @@
9
9
  ### Chores
10
10
  * n/a
11
11
 
12
+ ## [v0.1.0](https://github.com/elgalu/time_ago_in_words/tree/v0.1.0)
13
+
14
+ ### New Features
15
+ * n/a
16
+
17
+ ### Bugfixes
18
+ * Removed support for ruby 1.8.7 due to 'time ouf of range' errors. (Leo Gallucci)
19
+
20
+ ### Chores
21
+ * Applied Extract Method refactor on Time#ago_in_words(). (Leo Gallucci)
22
+
12
23
  ## [v0.0.1](https://github.com/elgalu/time_ago_in_words/tree/v0.0.1)
13
24
 
14
25
  ## First gem release
@@ -20,22 +20,34 @@ module TimeAgoInWords
20
20
  #
21
21
  # @note Inspired from http://stackoverflow.com/a/4136485/511069
22
22
  def ago_in_words
23
+ return 'a very very long time ago' if self.year < 1800
23
24
  secs = Time.now - self
24
25
  return 'just now' if secs > -1 && secs < 1
25
26
  return '' if secs <= -1
26
- return 'a very very long time ago' if secs > 60*60*24*100_000
27
- ary = [[60, :seconds], [60, :minutes], [24, :hours], [100_000, :days]].map{ |count, name|
27
+ pair = ago_in_words_pair(secs)
28
+ ary = ago_in_words_singularize(pair)
29
+ ary.size == 0 ? '' : ary.join(' and ') << ' ago'
30
+ end
31
+
32
+ private
33
+
34
+ # @private
35
+ def ago_in_words_pair(secs)
36
+ [[60, :seconds], [60, :minutes], [24, :hours], [100_000, :days]].map{ |count, name|
28
37
  if secs > 0
29
38
  secs, n = secs.divmod(count)
30
39
  "#{n.to_i} #{name}"
31
40
  end
32
41
  }.compact.reverse[0..1]
33
- if ary.size == 1
34
- ary.map! {|part| part[0, 2].to_i == 1 ? part.chomp('s') : part }
42
+ end
43
+
44
+ # @private
45
+ def ago_in_words_singularize(pair)
46
+ if pair.size == 1
47
+ pair.map! {|part| part[0, 2].to_i == 1 ? part.chomp('s') : part }
35
48
  else
36
- ary.map! {|part| part[0, 2].to_i == 1 ? part.chomp('s') : part[0, 2].to_i == 0 ? nil : part }
49
+ pair.map! {|part| part[0, 2].to_i == 1 ? part.chomp('s') : part[0, 2].to_i == 0 ? nil : part }
37
50
  end
38
- ary.compact!
39
- ary.size == 0 ? '' : ary.join(' and ') << ' ago'
51
+ pair.compact
40
52
  end
41
53
  end
@@ -1,3 +1,3 @@
1
1
  module TimeAgoInWords
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -16,15 +16,15 @@ describe TimeAgoInWords do
16
16
  it "returns empty string on future dates" do
17
17
  (Time.now + 1.6).ago_in_words.should == ''
18
18
  (Time.now + 100).ago_in_words.should == ''
19
- (Time.now + 100_000).ago_in_words.should == ''
19
+ (Time.now + 9999).ago_in_words.should == ''
20
20
  end
21
21
 
22
- it "returns 'a very very long time ago' when more than 250 years ago" do
23
- (Time.now - 60*60*24*100_001).ago_in_words.should == 'a very very long time ago'
22
+ it "returns 'a very very long time ago' when more than 300 years ago" do
23
+ Time.local(1713,01,01).ago_in_words.should == 'a very very long time ago'
24
24
  end
25
25
 
26
26
  it "can handle many days ago" do
27
- (Time.now - 60*60*24*99_999).ago_in_words.should == '99999 days ago'
27
+ (Time.now - 60*60*24*9999).ago_in_words.should == '9999 days ago'
28
28
  end
29
29
 
30
30
  it "returns N seconds ago, N seconds ago!" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_ago_in_words
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Gallucci