Class: Date::Deta
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#years ⇒ Object
readonly
Returns the value of attribute years.
Class Method Summary collapse
Instance Method Summary collapse
- #display(include_days = true) ⇒ Object
-
#initialize(days) ⇒ Deta
constructor
A new instance of Deta.
-
#to_a ⇒ Object
to [years months days].
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
#days ⇒ Object (readonly)
Returns the value of attribute days.
15 16 17 |
# File 'lib/tagen/date.rb', line 15 def days @days end |
#months ⇒ Object (readonly)
Returns the value of attribute months.
15 16 17 |
# File 'lib/tagen/date.rb', line 15 def months @months end |
#years ⇒ Object (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.
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_a ⇒ Object
to [years months days]
33 34 35 |
# File 'lib/tagen/date.rb', line 33 def to_a [ years, months, days ] end |