dotiw 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,3 @@
1
1
  ---
2
2
  BUNDLE_DISABLE_SHARED_GEMS: "1"
3
+ BUNDLE_WITHOUT: production
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dotiw (0.7.0)
4
+ dotiw (1.0.0)
5
5
  actionpack (~> 3.0.0)
6
6
 
7
7
  GEM
@@ -115,6 +115,20 @@ Using something other than ', and':
115
115
  >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, { :last_word_connector => ', finally ' })
116
116
  => "1 hour, 1 minute, finally 1 second"
117
117
 
118
+ #### :highest\_measure\_only
119
+
120
+ For times when Rails `distance_of_time_in_words` is not precise enough and `DOTIW` is too precise. For instance, if you only want to know the highest time part (measure) that elapsed between two dates.
121
+
122
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, { :highest_measure_only => true })
123
+ => "1 hour"
124
+
125
+ Notice how minutes and seconds were removed from the output. Another example:
126
+
127
+ >> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, { :highest_measure_only => true })
128
+ => "1 minute"
129
+
130
+ Minutes are the highest measure, so seconds were discarded from the output.
131
+
118
132
  ## distance\_of\_time
119
133
 
120
134
  If you have simply a number of seconds you can get the "stringified" version of this by using `distance_of_time`:
@@ -60,6 +60,8 @@ module ActionView
60
60
 
61
61
  output = []
62
62
 
63
+ time_measurements = Hash[*time_measurements.first] if options.delete(:highest_measure_only)
64
+
63
65
  time_measurements.each do |measure, key|
64
66
  name = options[:singularize] == :always || hash[key].between?(-1, 1) ? key.singularize : key
65
67
  output += ["#{hash[key]} #{name}"]
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module DOTIW
4
- VERSION = "0.7.0"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -199,10 +199,14 @@ describe "A better distance_of_time_in_words" do
199
199
  Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
200
200
  { "except" => "minutes" },
201
201
  "1 year, 2 months, 3 days, 4 hours, and 6 seconds"],
202
+ [Time.now,
203
+ Time.now + 1.hour + 2.minutes + 3.seconds,
204
+ { :highest_measure_only => true },
205
+ "1 hour"],
202
206
  [Time.now,
203
207
  Time.now + 2.year + 3.months + 4.days + 5.hours + 6.minutes + 7.seconds,
204
208
  { :singularize => :always },
205
- "2 year, 3 month, 4 day, 5 hour, 6 minute, and 7 second"]
209
+ "2 year, 3 month, 4 day, 4 hour, 6 minute, and 7 second"]
206
210
  ].each do |start, finish, options, output|
207
211
  it "should be #{output}" do
208
212
  distance_of_time_in_words(start, finish, true, options).should eql(output)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotiw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 7
9
9
  - 0
10
- version: 0.7.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Bigg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-23 00:00:00 +10:00
18
+ date: 2010-12-23 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency