class CountDownObj

CountDownObj - Count Down Object by Daniel P. Clark The MIT License

Constants

VERSION

Attributes

countdownto[RW]
day[R]
hour[R]
minute[R]
second[R]
week[R]

Public Class Methods

new(countdownto = (Time.now + @@day)) click to toggle source
# File lib/countdownobj.rb, line 21
def initialize(countdownto = (Time.now + @@day))
  self.countdownto = countdownto    
end

Public Instance Methods

deadline() click to toggle source
# File lib/countdownobj.rb, line 25
def deadline
  self.countdownto - Time.at(Time.now.to_f)
end
deadline=(timeObject) click to toggle source
# File lib/countdownobj.rb, line 57
def deadline=(timeObject)
  self.countdownto = Time.at(timeObject)
end
to_s() click to toggle source
# File lib/countdownobj.rb, line 29
def to_s
  out = ""
  val = []
  [[@@week, "week"], [@@day, "day"], [@@hour, "hour"], [@@minute, "minute"], [@@second, "second"]].each do |tm|
    if val.empty?
      val = deadline.divmod(tm[0])
    else
      val = val[1].divmod(tm[0])
    end
    if val[0] > 0
      out << "#{val[0]} "
      if val[0] > 1
        out << "#{tm[1]}s"
      else
        out << "#{tm[1]}"
      end
      if not tm[1] == "second"
        out << ", "
      end
    end
  end
  if deadline.to_i <= 0
    out = 'deadline'
  else
    out.chomp(", ")
  end
end