Class: Time::Deta

Inherits:
Object show all
Defined in:
lib/tagen/core/time.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ Deta

Returns a new instance of Deta.



24
25
26
27
28
29
30
31
# File 'lib/tagen/core/time.rb', line 24

def initialize(seconds)
  deta = seconds
  deta, @seconds = deta.divmod(60)
  deta, @minutes = deta.divmod(60)
  deta, @hours = deta.divmod(24)
  deta, @days = deta.divmod(30)
  @years, @months = deta.divmod(12)
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



22
23
24
# File 'lib/tagen/core/time.rb', line 22

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



22
23
24
# File 'lib/tagen/core/time.rb', line 22

def hours
  @hours
end

#minutesObject (readonly)

Returns the value of attribute minutes.



22
23
24
# File 'lib/tagen/core/time.rb', line 22

def minutes
  @minutes
end

#monthsObject (readonly)

Returns the value of attribute months.



22
23
24
# File 'lib/tagen/core/time.rb', line 22

def months
  @months
end

#secondsObject (readonly)

Returns the value of attribute seconds.



22
23
24
# File 'lib/tagen/core/time.rb', line 22

def seconds
  @seconds
end

#yearsObject (readonly)

Returns the value of attribute years.



22
23
24
# File 'lib/tagen/core/time.rb', line 22

def years
  @years
end

Class Method Details

.deta(from, to) ⇒ Time::Deta

Returns deta.

Parameters:

Returns:



16
17
18
19
# File 'lib/tagen/core/time.rb', line 16

def deta(from, to)
  seconds = (from-to).to_i
  self.new(seconds)
end

Instance Method Details

#display(include_seconds = true) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tagen/core/time.rb', line 33

def display(include_seconds=true)
  ret = ""
  ret << "#{years} years " unless years == 0
  ret << "#{months} months " unless months == 0
  ret << "#{days} days " unless days==0
  ret << "#{hours} hours " unless hours == 0
  ret << "#{minutes} minutes " unless minutes == 0
  ret << "#{seconds} seconds" if include_seconds

  ret
end

#to_aObject

to [years, months, days, hours minutes seconds]



46
47
48
# File 'lib/tagen/core/time.rb', line 46

def to_a
  [ years, months, days, hours, minutes, seconds ]
end