rext 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,11 @@
1
1
 
2
+ 0.6.1 / 2009-11-25
3
+ ==================
4
+
5
+ * Added Date#in_words_since[_now]
6
+ * Changed; Date/Time#in_words_since now returns nil when over 100 years
7
+ * Fixed Date/Time#in_words_since
8
+
2
9
  0.6.0 / 2009-11-18
3
10
  ==================
4
11
 
@@ -8,4 +8,9 @@ class Date
8
8
  Time.send form, year, month, day
9
9
  end
10
10
 
11
+ def in_words_since *args
12
+ to_time.in_words_since *args
13
+ end
14
+ alias :in_words_since_now :in_words_since
15
+
11
16
  end
@@ -13,13 +13,14 @@ class Time
13
13
  # 5.seconds.ago.in_words_since_now # => less than one minute
14
14
  # 5.days.ago.in_words_since_now # => 5 days
15
15
  # 1.month.ago.in_words_since_now # => 1 month
16
- # 101.years.ago.in_words_since_now # => hundreds of years
16
+ # 101.years.ago.in_words_since_now # => nil
17
17
  #
18
- # "the article was published #{article.created_at.in_words_since_now} ago"
18
+ # "the article was published #{article.created_at.in_words_since_now || 'hundreds of years' } ago"
19
19
  # # => the article was published 15 minutes ago
20
20
  #
21
21
 
22
22
  def in_words_since time = Time.now
23
+ time = time.to_time
23
24
  return if self > time
24
25
  seconds = (time - self).to_i
25
26
  # TODO: abstract this out
@@ -28,14 +29,13 @@ class Time
28
29
  n == 1 ? "one #{type}" : "#{n} #{type}s"
29
30
  end
30
31
  case seconds
31
- when 0..59 ; 'less than one minute'
32
- when 1.minute..59.minutes ; pluralize[:minute]
33
- when 1.hour..23.hours ; pluralize[:hour]
34
- when 1.day..6.days ; pluralize[:day]
35
- when 1.week..3.weeks ; pluralize[:week]
36
- when 1.month..11.months ; pluralize[:month]
32
+ when 0..60 ; 'less than one minute'
33
+ when 1.minute..60.minutes ; pluralize[:minute]
34
+ when 1.hour..24.hours ; pluralize[:hour]
35
+ when 1.day..7.days ; pluralize[:day]
36
+ when 1.week..4.weeks ; pluralize[:week]
37
+ when 1.month..12.months ; pluralize[:month]
37
38
  when 1.year..99.years ; pluralize[:year]
38
- else 'hundreds of years'
39
39
  end
40
40
  end
41
41
  alias :in_words_since_now :in_words_since
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rext
3
- VERSION = '0.6.0'
3
+ VERSION = '0.6.1'
4
4
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rext}
5
- s.version = "0.6.0"
5
+ s.version = "0.6.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
9
- s.date = %q{2009-11-18}
9
+ s.date = %q{2009-11-25}
10
10
  s.description = %q{Ruby extensions}
11
11
  s.email = %q{tj@vision-media.ca}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/rext.rb", "lib/rext/all.rb", "lib/rext/array.rb", "lib/rext/array/helpers.rb", "lib/rext/date.rb", "lib/rext/date/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/hash.rb", "lib/rext/hash/helpers.rb", "lib/rext/integer.rb", "lib/rext/integer/helpers.rb", "lib/rext/module.rb", "lib/rext/module/helpers.rb", "lib/rext/numeric.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/object.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/proc.rb", "lib/rext/proc/helpers.rb", "lib/rext/process.rb", "lib/rext/process/helpers.rb", "lib/rext/string.rb", "lib/rext/string/encode.rb", "lib/rext/string/helpers.rb", "lib/rext/symbol.rb", "lib/rext/symbol/helpers.rb", "lib/rext/time.rb", "lib/rext/time/helpers.rb", "lib/rext/version.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
@@ -15,7 +15,15 @@ describe Time do
15
15
  event -= 5.years
16
16
  event.in_words_since_now.should == '5 years'
17
17
  event -= 100.years
18
- event.in_words_since_now.should == 'hundreds of years'
18
+ event.in_words_since_now.should be_nil
19
+
20
+ event = Date.parse 'may 25 1987'
21
+ event.in_words_since_now.should == '22 years'
22
+ event.in_words_since(Date.parse('may 25 1989')).should == '2 years'
23
+
24
+ event = DateTime.parse 'may 25th 1987'
25
+ event.in_words_since_now.should == '22 years'
26
+ event.in_words_since(Date.parse('may 25 1989')).should == '2 years'
19
27
  end
20
28
  end
21
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-18 00:00:00 -08:00
12
+ date: 2009-11-25 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15