Class: Kuby::Docker::TimestampTag
- Inherits:
-
Object
- Object
- Kuby::Docker::TimestampTag
- Defined in:
- lib/kuby/docker/timestamp_tag.rb
Constant Summary collapse
- FORMAT =
extend T::Sig
'%Y%m%d%H%M%S'.freeze
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
T::Sig::WithoutRuntime.sig { returns(Time) }.
Class Method Summary collapse
-
.now ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::TimestampTag) }.
-
.try_parse(str) ⇒ Object
T::Sig::WithoutRuntime.sig { params(str: T.nilable(String)).returns(T.nilable(Kuby::Docker::TimestampTag)) }.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
T::Sig::WithoutRuntime.sig { params(other: Kuby::Docker::TimestampTag).returns(T.nilable(Integer)) }.
-
#==(other) ⇒ Object
T::Sig::WithoutRuntime.sig { params(other: Kuby::Docker::TimestampTag).returns(T::Boolean) }.
-
#eql?(other) ⇒ Boolean
T::Sig::WithoutRuntime.sig { params(other: Kuby::Docker::TimestampTag).returns(T::Boolean) }.
-
#hash ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Integer) }.
-
#initialize(time) ⇒ TimestampTag
constructor
T::Sig::WithoutRuntime.sig { params(time: Time).void }.
-
#to_s ⇒ Object
T::Sig::WithoutRuntime.sig { returns(String) }.
Constructor Details
#initialize(time) ⇒ TimestampTag
T::Sig::WithoutRuntime.sig { params(time: Time).void }
39 40 41 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 39 def initialize(time) @time = time end |
Instance Attribute Details
#time ⇒ Object (readonly)
T::Sig::WithoutRuntime.sig { returns(Time) }
36 37 38 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 36 def time @time end |
Class Method Details
.now ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::TimestampTag) }
31 32 33 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 31 def self.now new(Time.now.utc) end |
.try_parse(str) ⇒ Object
T::Sig::WithoutRuntime.sig { params(str: T.nilable(String)).returns(T.nilable(Kuby::Docker::TimestampTag)) }
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
T::Sig::WithoutRuntime.sig { params(other: Kuby::Docker::TimestampTag).returns(T.nilable(Integer)) }
49 50 51 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 49 def <=>(other) time <=> other.time end |
#==(other) ⇒ Object
T::Sig::WithoutRuntime.sig { params(other: Kuby::Docker::TimestampTag).returns(T::Boolean) }
54 55 56 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 54 def ==(other) time == other.time end |
#eql?(other) ⇒ Boolean
T::Sig::WithoutRuntime.sig { params(other: Kuby::Docker::TimestampTag).returns(T::Boolean) }
64 65 66 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 64 def eql?(other) time == other.time end |
#hash ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Integer) }
59 60 61 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 59 def hash time.hash end |
#to_s ⇒ Object
T::Sig::WithoutRuntime.sig { returns(String) }
44 45 46 |
# File 'lib/kuby/docker/timestamp_tag.rb', line 44 def to_s time.strftime(FORMAT) end |