Class: Zold::Age

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/age.rb

Overview

Age

Instance Method Summary collapse

Constructor Details

#initialize(time, limit: nil) ⇒ Age

Returns a new instance of Age.



34
35
36
37
# File 'lib/zold/age.rb', line 34

def initialize(time, limit: nil)
  @time = time.nil? || time.is_a?(Time) ? time : Txn.parse_time(time)
  @limit = limit
end

Instance Method Details

#to_sObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/zold/age.rb', line 39

def to_s
  return '?' if @time.nil?
  sec = Time.now - @time
  txt = text(sec)
  if !@limit.nil? && sec > @limit
    Rainbow(txt).red
  else
    txt
  end
end