Class: CdT::TimeDuration
- Inherits:
-
Object
show all
- Defined in:
- lib/menstruacion/time-duration.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
21
22
23
|
# File 'lib/menstruacion/time-duration.rb', line 21
def initialize(amount)
@amount_of_seconds = amount * self.class::CONVERTION_CONSTANT
end
|
Class Method Details
.[](amount) ⇒ Object
15
16
17
|
# File 'lib/menstruacion/time-duration.rb', line 15
def self.[](amount)
self.new(amount).freeze
end
|
.from(from_date_time, to:) ⇒ Object
11
12
13
|
# File 'lib/menstruacion/time-duration.rb', line 11
def self.from(from_date_time, to:)
from_seconds( (to - from_date_time) * Days::CONVERTION_CONSTANT)
end
|
.from_seconds(amount_of_seconds) ⇒ Object
5
6
7
8
9
|
# File 'lib/menstruacion/time-duration.rb', line 5
def self.from_seconds(amount_of_seconds)
self.new(0).tap { |duration|
duration.set_amount_of_seconds(amount_of_seconds)
}.freeze
end
|
Instance Method Details
#*(scalar) ⇒ Object
75
76
77
|
# File 'lib/menstruacion/time-duration.rb', line 75
def *(scalar)
self.class.from_seconds(amount_of_seconds * scalar)
end
|
#+(time_duration) ⇒ Object
67
68
69
|
# File 'lib/menstruacion/time-duration.rb', line 67
def +(time_duration)
self.class.from_seconds(amount_of_seconds + time_duration.amount_of_seconds)
end
|
#-(time_duration) ⇒ Object
71
72
73
|
# File 'lib/menstruacion/time-duration.rb', line 71
def -(time_duration)
self.class.from_seconds(amount_of_seconds - time_duration.amount_of_seconds)
end
|
#/(scalar) ⇒ Object
79
80
81
|
# File 'lib/menstruacion/time-duration.rb', line 79
def /(scalar)
self.class.from_seconds(amount_of_seconds.to_f / scalar)
end
|
#<(time_duration) ⇒ Object
85
86
87
|
# File 'lib/menstruacion/time-duration.rb', line 85
def <(time_duration)
amount_of_seconds < time_duration.amount_of_seconds
end
|
#<=(time_duration) ⇒ Object
89
90
91
|
# File 'lib/menstruacion/time-duration.rb', line 89
def <=(time_duration)
amount_of_seconds <= time_duration.amount_of_seconds
end
|
#==(time_duration) ⇒ Object
101
102
103
|
# File 'lib/menstruacion/time-duration.rb', line 101
def ==(time_duration)
amount_of_seconds == time_duration.amount_of_seconds
end
|
#>(time_duration) ⇒ Object
93
94
95
|
# File 'lib/menstruacion/time-duration.rb', line 93
def >(time_duration)
amount_of_seconds > time_duration.amount_of_seconds
end
|
#>=(time_duration) ⇒ Object
97
98
99
|
# File 'lib/menstruacion/time-duration.rb', line 97
def >=(time_duration)
amount_of_seconds >= time_duration.amount_of_seconds
end
|
#amount_of_seconds ⇒ Object
27
28
29
|
# File 'lib/menstruacion/time-duration.rb', line 27
def amount_of_seconds
@amount_of_seconds
end
|
#as_days ⇒ Object
57
58
59
|
# File 'lib/menstruacion/time-duration.rb', line 57
def as_days()
Days.from_seconds(amount_of_seconds)
end
|
#as_hours ⇒ Object
53
54
55
|
# File 'lib/menstruacion/time-duration.rb', line 53
def as_hours()
Hours.from_seconds(amount_of_seconds)
end
|
#as_minutes ⇒ Object
49
50
51
|
# File 'lib/menstruacion/time-duration.rb', line 49
def as_minutes()
Minutes.from_seconds(amount_of_seconds)
end
|
#as_seconds ⇒ Object
45
46
47
|
# File 'lib/menstruacion/time-duration.rb', line 45
def as_seconds()
Seconds.from_seconds(amount_of_seconds)
end
|
#as_weeks ⇒ Object
61
62
63
|
# File 'lib/menstruacion/time-duration.rb', line 61
def as_weeks()
Weeks.from_seconds(amount_of_seconds)
end
|
#set_amount_of_seconds(amount_of_seconds) ⇒ Object
Private - Set the amount of seconds
106
107
108
|
# File 'lib/menstruacion/time-duration.rb', line 106
def set_amount_of_seconds(amount_of_seconds)
@amount_of_seconds = amount_of_seconds
end
|
#to_f ⇒ Object
37
38
39
|
# File 'lib/menstruacion/time-duration.rb', line 37
def to_f()
amount_of_seconds.to_f / self.class::CONVERTION_CONSTANT
end
|
#to_i ⇒ Object
41
42
43
|
# File 'lib/menstruacion/time-duration.rb', line 41
def to_i()
to_f.to_i
end
|
#units ⇒ Object
31
32
33
|
# File 'lib/menstruacion/time-duration.rb', line 31
def units
CdT.subclass_responsibility
end
|