Class: Numeric

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

Instance Method Summary collapse

Instance Method Details

#agoObject



50
51
52
# File 'lib/durations.rb', line 50

def ago
	Time.now-self
end

#days(*args) ⇒ Object Also known as: day

Synopsis

2.days # => 172800
2.days 5.hours, 15.minutes, 45.seconds # => 191745


33
34
35
# File 'lib/durations.rb', line 33

def days(*args)
	args.inject(self*86400) { |s,a| s+a }
end

#from_nowObject



54
55
56
# File 'lib/durations.rb', line 54

def from_now
	Time.now+self
end

#hours(*args) ⇒ Object Also known as: hour

Synopsis

5.hours # => 18000
5.hours 15.minutes, 45.seconds # => 18945


26
27
28
# File 'lib/durations.rb', line 26

def hours(*args)
	args.inject(self*3600) { |s,a| s+a }
end

#minutes(*args) ⇒ Object Also known as: minute

Synopsis

15.minutes # => 900
15.minutes 45.seconds # => 945


19
20
21
# File 'lib/durations.rb', line 19

def minutes(*args)
	args.inject(self*60) { |s,a| s+a }
end

#seconds(*args) ⇒ Object Also known as: second

Synopsis

45.seconds # => 45


12
13
14
# File 'lib/durations.rb', line 12

def seconds(*args)
	args.inject(self) { |s,a| s+a }
end

#weeks(*args) ⇒ Object Also known as: week

Synopsis

1.week # => 604800
1.week 2.days, 5.hours, 15.minutes, 45.seconds # => 796545


40
41
42
# File 'lib/durations.rb', line 40

def weeks(*args)
	args.inject(self*604800) { |s,a| s+a }
end