Class: Kuby::Docker::TimestampTag

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/kuby/docker/timestamp_tag.rb

Constant Summary collapse

FORMAT =
T.let('%Y%m%d%H%M%S'.freeze, String)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time) ⇒ TimestampTag

Returns a new instance of TimestampTag.



27
28
29
# File 'lib/kuby/docker/timestamp_tag.rb', line 27

def initialize(time)
  @time = T.let(time, Time)
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



24
25
26
# File 'lib/kuby/docker/timestamp_tag.rb', line 24

def time
  @time
end

Class Method Details

.try_parse(str) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/kuby/docker/timestamp_tag.rb', line 13

def self.try_parse(str)
  time = begin
    Time.strptime(str, FORMAT)
  rescue ArgumentError
    return nil
  end

  new(time)
end

Instance Method Details

#<=>(other) ⇒ Object



37
38
39
# File 'lib/kuby/docker/timestamp_tag.rb', line 37

def <=>(other)
  time <=> other.time
end

#==(other) ⇒ Object



42
43
44
# File 'lib/kuby/docker/timestamp_tag.rb', line 42

def ==(other)
  time == other.time
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/kuby/docker/timestamp_tag.rb', line 52

def eql?(other)
  time == other.time
end

#hashObject



47
48
49
# File 'lib/kuby/docker/timestamp_tag.rb', line 47

def hash
  time.hash
end

#to_sObject



32
33
34
# File 'lib/kuby/docker/timestamp_tag.rb', line 32

def to_s
  time.strftime(FORMAT)
end