os/mac/version: add strip_patch method

This commit is contained in:
Bo Anderson 2021-02-09 18:34:47 +00:00
parent 71d81a8611
commit 61cda1465f

View File

@ -78,19 +78,21 @@ module OS
end end
end end
sig { returns(Symbol) } sig { returns(T.self_type) }
def to_sym def strip_patch
@to_sym ||= begin # Big Sur is 11.x but Catalina is 10.15.x.
# Big Sur is 11.x but Catalina is 10.15. if major >= 11
major_macos = if major >= 11 self.class.new(major.to_s)
major
else else
major_minor major_minor
end.to_s
SYMBOLS.invert.fetch(major_macos, :dunno)
end end
end end
sig { returns(Symbol) }
def to_sym
@to_sym ||= SYMBOLS.invert.fetch(strip_patch.to_s, :dunno)
end
sig { returns(String) } sig { returns(String) }
def pretty_name def pretty_name
@pretty_name ||= to_sym.to_s.split("_").map(&:capitalize).join(" ").freeze @pretty_name ||= to_sym.to_s.split("_").map(&:capitalize).join(" ").freeze