2024-04-25 17:00:02 -04:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-17 02:58:03 +02:00
|
|
|
# A formula's checksum.
|
2012-06-18 19:58:35 -05:00
|
|
|
class Checksum
|
2017-06-26 07:30:28 +02:00
|
|
|
extend Forwardable
|
|
|
|
|
2024-04-25 17:00:02 -04:00
|
|
|
sig { returns(String) }
|
2021-01-07 08:33:57 +01:00
|
|
|
attr_reader :hexdigest
|
2012-06-18 19:58:35 -05:00
|
|
|
|
2024-04-25 17:00:02 -04:00
|
|
|
sig { params(hexdigest: String).void }
|
2021-01-07 08:33:57 +01:00
|
|
|
def initialize(hexdigest)
|
2024-04-25 17:00:02 -04:00
|
|
|
@hexdigest = T.let(hexdigest.downcase, String)
|
2012-06-18 19:58:35 -05:00
|
|
|
end
|
|
|
|
|
2020-11-19 18:12:16 +01:00
|
|
|
delegate [:empty?, :to_s, :length, :[]] => :@hexdigest
|
2012-06-18 19:58:35 -05:00
|
|
|
|
2024-04-25 17:00:02 -04:00
|
|
|
sig { params(other: T.any(String, Checksum, Symbol)).returns(T::Boolean) }
|
2013-04-07 00:49:56 -05:00
|
|
|
def ==(other)
|
2020-11-19 18:12:16 +01:00
|
|
|
case other
|
|
|
|
when String
|
|
|
|
to_s == other.downcase
|
|
|
|
when Checksum
|
2021-01-07 08:33:57 +01:00
|
|
|
hexdigest == other.hexdigest
|
2020-11-19 18:12:16 +01:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
2012-06-18 19:58:35 -05:00
|
|
|
end
|
|
|
|
end
|