Class: Date::Deta

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(days) ⇒ Deta

Returns a new instance of Deta.



17
18
19
20
21
# File 'lib/tagen/date.rb', line 17

def initialize(days)
  deta = days
  deta, @days = deta.divmod(30)
  @years, @months = deta.divmod(12)
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



15
16
17
# File 'lib/tagen/date.rb', line 15

def days
  @days
end

#monthsObject (readonly)

Returns the value of attribute months.



15
16
17
# File 'lib/tagen/date.rb', line 15

def months
  @months
end

#yearsObject (readonly)

Returns the value of attribute years.



15
16
17
# File 'lib/tagen/date.rb', line 15

def years
  @years
end

Class Method Details

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

Returns deta.

Parameters:

Returns:



9
10
11
12
# File 'lib/tagen/date.rb', line 9

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

Instance Method Details

#display(include_days = true) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/tagen/date.rb', line 23

def display(include_days=true)
  ret = ""
  ret << "#{years} years " unless years == 0
  ret << "#{months} months " unless months == 0
  ret << "#{days} days" unless (!include_days && days==0)

  ret
end

#to_aObject

to [years months days]



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

def to_a
  [ years, months, days ]
end