duration 0.0.1 → 0.0.2
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.
- data/lib/duration.rb +25 -0
- metadata +2 -2
data/lib/duration.rb
CHANGED
@@ -211,4 +211,29 @@ class Duration
|
|
211
211
|
end
|
212
212
|
|
213
213
|
alias to_i total
|
214
|
+
end
|
215
|
+
|
216
|
+
class Numeric
|
217
|
+
alias __Numeric_method_missing method_missing
|
218
|
+
|
219
|
+
# Intercept calls to #weeks, #days, #hours, #minutes, #seconds because Rails
|
220
|
+
# defines their own methods, so I'd like to prevent any redefining of Rails'
|
221
|
+
# methods.
|
222
|
+
#
|
223
|
+
# *Example*
|
224
|
+
#
|
225
|
+
# 140.seconds
|
226
|
+
# => #<Duration: 2 minutes and 20 seconds>
|
227
|
+
#
|
228
|
+
def method_missing(method, *args)
|
229
|
+
case method
|
230
|
+
when :weeks then Duration.new(Duration::WEEK * self)
|
231
|
+
when :days then Duration.new(Duration::DAY * self)
|
232
|
+
when :hours then Duration.new(Duration::HOUR * self)
|
233
|
+
when :minutes then Duration.new(Duration::MINUTE * self)
|
234
|
+
when :seconds then Duration.new(Duration::SECOND * self)
|
235
|
+
else
|
236
|
+
__Numeric_method_missing(method, *args)
|
237
|
+
end
|
238
|
+
end
|
214
239
|
end
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: duration
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
6
|
+
version: 0.0.2
|
7
7
|
date: 2006-05-23 00:00:00 +09:00
|
8
8
|
summary: Duration is a package for manipulating time spans.
|
9
9
|
require_paths:
|
@@ -12,7 +12,7 @@ email: shugotenshi@gmail.com
|
|
12
12
|
homepage: http://duration.rubyforge.org
|
13
13
|
rubyforge_project: duration
|
14
14
|
description: Duration is a simple class that provides ways of easily manipulating durations (timespans) and formatting them as well.
|
15
|
-
autorequire:
|
15
|
+
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: true
|