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.



34
35
36
# File 'lib/kuby/docker/timestamp_tag.rb', line 34

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

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



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

def time
  @time
end

Class Method Details

.try_parse(str) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kuby/docker/timestamp_tag.rb', line 13

def self.try_parse(str)
  return nil unless str

  # The strptime function stops scanning after the pattern has been matched, so
  # we check for all numbers here to prevent things like 20210424165405-assets
  # from being treated as a timestamp tag.
  return nil unless str =~ /\A\d+\z/

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

  new(time)
end

Instance Method Details

#<=>(other) ⇒ Object



44
45
46
# File 'lib/kuby/docker/timestamp_tag.rb', line 44

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

#==(other) ⇒ Object



49
50
51
# File 'lib/kuby/docker/timestamp_tag.rb', line 49

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/kuby/docker/timestamp_tag.rb', line 59

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

#hashObject



54
55
56
# File 'lib/kuby/docker/timestamp_tag.rb', line 54

def hash
  time.hash
end

#to_sObject



39
40
41
# File 'lib/kuby/docker/timestamp_tag.rb', line 39

def to_s
  time.strftime(FORMAT)
end