Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/durations.rb

Instance Method Summary collapse

Instance Method Details

#agoObject



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_nowObject



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