Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/durations.rb
Instance Method Summary collapse
- #ago ⇒ Object
-
#days(*args) ⇒ Object
Synopsis 2.days # => 172800 2.days 5.hours, 15.minutes, 45.seconds # => 191745.
- #from_now ⇒ Object
-
#hours(*args) ⇒ Object
Synopsis 5.hours # => 18000 5.hours 15.minutes, 45.seconds # => 18945.
-
#minutes(*args) ⇒ Object
Synopsis 15.minutes # => 900 15.minutes 45.seconds # => 945.
-
#seconds(*args) ⇒ Object
Synopsis 45.seconds # => 45.
-
#weeks(*args) ⇒ Object
Synopsis 1.week # => 604800 1.week 2.days, 5.hours, 15.minutes, 45.seconds # => 796545.
Instance Method Details
#ago ⇒ Object
63 64 65 |
# File 'lib/durations.rb', line 63 def ago Time.now-self end |
#days(*args) ⇒ Object
Synopsis
2.days # => 172800
2.days 5.hours, 15.minutes, 45.seconds # => 191745
52 53 54 |
# File 'lib/durations.rb', line 52 def days(*args) args.inject(self*86400) { |s,a| s+a } end |
#from_now ⇒ Object
67 68 69 |
# File 'lib/durations.rb', line 67 def from_now Time.now+self end |
#hours(*args) ⇒ Object
Synopsis
5.hours # => 18000
5.hours 15.minutes, 45.seconds # => 18945
45 46 47 |
# File 'lib/durations.rb', line 45 def hours(*args) args.inject(self*3600) { |s,a| s+a } end |
#minutes(*args) ⇒ Object
Synopsis
15.minutes # => 900
15.minutes 45.seconds # => 945
38 39 40 |
# File 'lib/durations.rb', line 38 def minutes(*args) args.inject(self*60) { |s,a| s+a } end |
#seconds(*args) ⇒ Object
Synopsis
45.seconds # => 45
31 32 33 |
# File 'lib/durations.rb', line 31 def seconds(*args) args.inject(self) { |s,a| s+a } end |
#weeks(*args) ⇒ Object
Synopsis
1.week # => 604800
1.week 2.days, 5.hours, 15.minutes, 45.seconds # => 796545
59 60 61 |
# File 'lib/durations.rb', line 59 def weeks(*args) args.inject(self*604800) { |s,a| s+a } end |