time_sentence 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -5,46 +5,49 @@ into joy.
5
5
 
6
6
  ## Basic Usage
7
7
 
8
- You can use the `time_sentence` method on any number or the Time.sentence class method to get the same result
8
+ You can use the `to_time_sentence` method on any number or the `Time.to_sentence` class method to get the same result
9
9
 
10
10
  ```ruby
11
- 1.hour.time_sentence #=> "1 hour"
12
- 168.hours.time_sentence #=> "1 week"
13
- 9999.seconds.time_sentence #=> "2 hours, 46 minutes, 39 seconds"
14
- 123456876543.seconds.time_sentence #=> "4 millennia, 25 decades, 2 years"
15
-
16
- Time.sentence(1.hour) #=> "1 hour"
17
- Time.sentence(168.hours) #=> "1 week"
18
- Time.sentence(9999.seconds) #=> "2 hours, 46 minutes, 39 seconds"
19
- Time.sentence(123456876543.seconds) #=> "4 millennia, 25 decades, 2 years"
11
+ 1.hour.to_time_sentence #=> "1 hour"
12
+ 168.hours.to_time_sentence #=> "1 week"
13
+ 525600.minutes.to_time_sentence #=> "1 year, 1 month, 1 day"
14
+ 9999.seconds.to_time_sentence #=> "2 hours, 46 minutes, 39 seconds"
15
+ 123456876543.seconds.to_time_sentence #=> "4 millennia, 25 decades, 2 years"
16
+
17
+ Time.to_sentence(1.hour) #=> "1 hour"
18
+ Time.to_sentence(168.hours) #=> "1 week"
19
+ Time.to_sentence(525600.minutes) #=> "1 year, 1 month, 1 day"
20
+ Time.to_sentence(9999.seconds) #=> "2 hours, 46 minutes, 39 seconds"
21
+ Time.to_sentence(123456876543.seconds) #=> "4 millennia, 25 decades, 2 years"
20
22
  ```
21
23
 
22
24
  ## Advanced Usage
23
25
 
24
26
  ### Specificity
25
27
 
26
- Time_Sentence assumes that you won't want more than 3 terms in your sentence, so it chooses the largest unit it can,
28
+ `time_sentence` assumes that you won't want more than 3 terms in your sentence, so it chooses the largest unit it can,
27
29
  then displays the next smaller 2 (that don't equal 0) as well. For example:
28
30
 
29
31
  ```ruby
30
- 123456877.seconds.time_sentence #=> "4 years, 3 months, 21 hours"
32
+ 123456877.seconds.to_time_sentence #=> "4 years, 3 months, 21 hours"
31
33
  ```
32
34
 
33
35
  Normally if you have a number on the scale of years, it doesn't matter how many, say, seconds there are. The number
34
- above represents 4 years, 3 months, 0 weeks, 0 days, 21 hours, and probably some number if minutes and seconds.
36
+ above represents 4 years, 3 months, 0 weeks, 0 days, 21 hours, and probably some number of minutes and seconds.
35
37
 
36
38
  If we actually *do* care about those minutes and seconds, we can pass a specificity argument in to make the sentence
37
39
  more (or less specific). For example:
38
40
 
39
41
  ```ruby
40
- 123456877.seconds.time_sentence #=> "4 years, 3 months, 21 hours"
41
- 123456877.seconds.time_sentence(1) #=> "4 years"
42
- 123456877.seconds.time_sentence(2) #=> "4 years, 3 months"
43
- 123456877.seconds.time_sentence(3) #=> "4 years, 3 months, 21 hours"
44
- 123456877.seconds.time_sentence(4) #=> "4 years, 3 months, 21 hours, 34 minutes"
45
- 123456877.seconds.time_sentence(5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds"
46
-
47
- Time.sentence(123456877.seconds, 5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds"
42
+ 123456877.seconds.to_time_sentence #=> "4 years, 3 months, 21 hours"
43
+ 123456877.seconds.to_time_sentence(1) #=> "4 years"
44
+ 123456877.seconds.to_time_sentence(2) #=> "4 years, 3 months"
45
+ 123456877.seconds.to_time_sentence(3) #=> "4 years, 3 months, 21 hours"
46
+ 123456877.seconds.to_time_sentence(4) #=> "4 years, 3 months, 21 hours, 34 minutes"
47
+ 123456877.seconds.to_time_sentence(5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds"
48
+
49
+ # Works the same way by calling Time.to_sentence
50
+ Time.to_sentence(123456877.seconds, 5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds"
48
51
  ```
49
52
 
50
53
  ### Past Times
@@ -52,7 +55,7 @@ more (or less specific). For example:
52
55
  Passing a negative number into the method will generate a sentence about the past:
53
56
 
54
57
  ```ruby
55
- -123456877.seconds.time_sentence(5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds ago"
58
+ -123456877.seconds.to_time_sentence(5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds ago"
56
59
  ```
57
60
 
58
61
  ### Now
@@ -60,12 +63,12 @@ Passing a negative number into the method will generate a sentence about the pas
60
63
  Passing 0 into the method will simply return "now"
61
64
 
62
65
  ```ruby
63
- 0.seconds.time_sentence #=> "now"
66
+ 0.seconds.to_time_sentence #=> "now"
64
67
  ```
65
68
 
66
69
  # Contributors
67
70
 
68
- time_sentence is solely Pete Michaud's (me@petermichaud.com) fault, so blame him for everything.
71
+ `time_sentence` is solely Pete Michaud's (me@petermichaud.com) fault, so blame him for everything.
69
72
 
70
73
  # License
71
74
 
@@ -1,5 +1,6 @@
1
1
  class Numeric
2
- def time_sentence specificity = 3
3
- Time.sentence(self, specificity)
2
+ def to_time_sentence specificity = 3
3
+ Time.to_sentence(self, specificity)
4
4
  end
5
+ alias_method :to_ts, :to_time_sentence
5
6
  end
data/lib/ext/ts_time.rb CHANGED
@@ -4,17 +4,17 @@ class Time
4
4
  #
5
5
  # == Examples
6
6
  #
7
- # Time.sentence(1.hour) #=> "1 hour"
8
- # Time.sentence(168.hours) #=> "1 week"
9
- # Time.sentence(9999.seconds) #=> "2 hours, 46 minutes, 39 seconds"
10
- # Time.sentence(123456876543.seconds) #=> "4 millennia, 25 decades, 2 years"
7
+ # Time.to_sentence(1.hour) #=> "1 hour"
8
+ # Time.to_sentence(168.hours) #=> "1 week"
9
+ # Time.to_sentence(9999.seconds) #=> "2 hours, 46 minutes, 39 seconds"
10
+ # Time.to_sentence(123456876543.seconds) #=> "4 millennia, 25 decades, 2 years"
11
11
  #
12
12
  # == Params
13
13
  #
14
14
  # @param [Numeric] Number of seconds to convert to a sentence
15
15
  # @param [Integer] Specificity of the sentence (how many clauses are included)
16
16
  # @return [String] Generated sentence
17
- def self.sentence seconds, specificity = 3
17
+ def self.to_sentence seconds, specificity = 3
18
18
 
19
19
  return 'now' if seconds == 0
20
20
 
@@ -1,3 +1,3 @@
1
1
  module TimeSentence
2
- VERSION = '0.0.4'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,39 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Time.sentence' do
3
+ describe 'Time.to_sentence' do
4
4
 
5
5
  it "should accept a positive integer" do
6
- Time.sentence(100000000).should eql "3 years, 5 months, 1 week"
7
- 100000000.time_sentence.should eql "3 years, 5 months, 1 week"
6
+ Time.to_sentence(100000000).should eql "3 years, 5 months, 1 week"
7
+ 100000000.to_time_sentence.should eql "3 years, 5 months, 1 week"
8
8
  end
9
9
 
10
10
  it "should accept a negative integer" do
11
- Time.sentence(-3600).should eql "1 hour ago"
12
- -3600.time_sentence.should eql "1 hour ago"
11
+ Time.to_sentence(-3600).should eql "1 hour ago"
12
+ -3600.to_time_sentence.should eql "1 hour ago"
13
13
  end
14
14
 
15
15
  it "should accept 0" do
16
- Time.sentence(0).should eql "now"
17
- 0.time_sentence.should eql "now"
16
+ Time.to_sentence(0).should eql "now"
17
+ 0.to_time_sentence.should eql "now"
18
18
  end
19
19
 
20
20
  it "should accept a very large number" do
21
- Time.sentence(100000000000000000000000).should be_kind_of String
22
- 100000000000000000000000.time_sentence.should be_kind_of String
21
+ Time.to_sentence(100000000000000000000000).should be_kind_of String
22
+ 100000000000000000000000.to_time_sentence.should be_kind_of String
23
23
  end
24
24
 
25
25
  it "should accept specificity" do
26
26
  (1..10).each do |specificity|
27
- Time.sentence(123456789123456789, specificity).should be_kind_of String
28
- 123456789123456789.time_sentence(specificity).should be_kind_of String
27
+ Time.to_sentence(123456789123456789, specificity).should be_kind_of String
28
+ 123456789123456789.to_time_sentence(specificity).should be_kind_of String
29
29
  end
30
30
  end
31
31
 
32
32
  it "should ignore a specificity that is out of range" do
33
- Time.sentence(123456789123456789, -5).should be_kind_of String
34
- 123456789123456789.time_sentence(-5).should be_kind_of String
35
- Time.sentence(123456789123456789, 20).should be_kind_of String
36
- 123456789123456789.time_sentence(20).should be_kind_of String
33
+ Time.to_sentence(123456789123456789, -5).should be_kind_of String
34
+ 123456789123456789.to_time_sentence(-5).should be_kind_of String
35
+ Time.to_sentence(123456789123456789, 20).should be_kind_of String
36
+ 123456789123456789.to_time_sentence(20).should be_kind_of String
37
37
  end
38
38
 
39
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_sentence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-14 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake