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.



17
18
19
20
# File 'lib/zold/age.rb', line 17

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



22
23
24
25
26
27
28
29
30
31
# File 'lib/zold/age.rb', line 22

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