class CdT::TimeDuration

Public Class Methods

[](amount) click to toggle source
# File lib/menstruacion/time-duration.rb, line 15
def self.[](amount)
        self.new(amount).freeze
end
from(from_date_time, to:) click to toggle source
# 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) click to toggle source

Creating instances

# 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
new(amount) click to toggle source

Initializing

# File lib/menstruacion/time-duration.rb, line 21
def initialize(amount)
        @amount_of_seconds = amount * self.class::CONVERTION_CONSTANT
end

Public Instance Methods

*(scalar) click to toggle source
# File lib/menstruacion/time-duration.rb, line 75
def *(scalar)
        self.class.from_seconds(amount_of_seconds * scalar)
end
+(time_duration) click to toggle source

Arithmetic

# 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) click to toggle source
# 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) click to toggle source
# File lib/menstruacion/time-duration.rb, line 79
def /(scalar)
        self.class.from_seconds(amount_of_seconds.to_f / scalar)
end
<(time_duration) click to toggle source

Comparing

# File lib/menstruacion/time-duration.rb, line 85
def <(time_duration)
        amount_of_seconds < time_duration.amount_of_seconds
end
<=(time_duration) click to toggle source
# File lib/menstruacion/time-duration.rb, line 89
def <=(time_duration)
        amount_of_seconds <= time_duration.amount_of_seconds
end
==(time_duration) click to toggle source
# File lib/menstruacion/time-duration.rb, line 101
def ==(time_duration)
        amount_of_seconds == time_duration.amount_of_seconds
end
>(time_duration) click to toggle source
# File lib/menstruacion/time-duration.rb, line 93
def >(time_duration)
        amount_of_seconds > time_duration.amount_of_seconds
end
>=(time_duration) click to toggle source
# File lib/menstruacion/time-duration.rb, line 97
def >=(time_duration)
        amount_of_seconds >= time_duration.amount_of_seconds
end
amount_of_seconds() click to toggle source

Accessing

# File lib/menstruacion/time-duration.rb, line 27
def amount_of_seconds
        @amount_of_seconds
end
as_days() click to toggle source
# File lib/menstruacion/time-duration.rb, line 57
def as_days()
        Days.from_seconds(amount_of_seconds)
end
as_hours() click to toggle source
# File lib/menstruacion/time-duration.rb, line 53
def as_hours()
        Hours.from_seconds(amount_of_seconds)
end
as_minutes() click to toggle source
# File lib/menstruacion/time-duration.rb, line 49
def as_minutes()
        Minutes.from_seconds(amount_of_seconds)
end
as_seconds() click to toggle source
# File lib/menstruacion/time-duration.rb, line 45
def as_seconds()
        Seconds.from_seconds(amount_of_seconds)
end
as_weeks() click to toggle source
# 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) click to toggle source

Private - Set the amount of seconds

# 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() click to toggle source

Converting

# File lib/menstruacion/time-duration.rb, line 37
def to_f()
        amount_of_seconds.to_f / self.class::CONVERTION_CONSTANT
end
to_i() click to toggle source
# File lib/menstruacion/time-duration.rb, line 41
def to_i()
        to_f.to_i
end
units() click to toggle source
# File lib/menstruacion/time-duration.rb, line 31
def units
        CdT.subclass_responsibility
end