Class: Time::Deta
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
-
#years ⇒ Object
readonly
Returns the value of attribute years.
Class Method Summary collapse
Instance Method Summary collapse
- #display(include_seconds = true) ⇒ Object
-
#initialize(seconds) ⇒ Deta
constructor
A new instance of Deta.
-
#to_a ⇒ Object
to [years, months, days, hours minutes seconds].
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
#days ⇒ Object (readonly)
Returns the value of attribute days.
22 23 24 |
# File 'lib/tagen/core/time.rb', line 22 def days @days end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
22 23 24 |
# File 'lib/tagen/core/time.rb', line 22 def hours @hours end |
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
22 23 24 |
# File 'lib/tagen/core/time.rb', line 22 def minutes @minutes end |
#months ⇒ Object (readonly)
Returns the value of attribute months.
22 23 24 |
# File 'lib/tagen/core/time.rb', line 22 def months @months end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
22 23 24 |
# File 'lib/tagen/core/time.rb', line 22 def seconds @seconds end |
#years ⇒ Object (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.
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_a ⇒ Object
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 |