diff --git a/Library/Homebrew/cask/dsl/version.rb b/Library/Homebrew/cask/dsl/version.rb index e2574db729..1de6ed2ccd 100644 --- a/Library/Homebrew/cask/dsl/version.rb +++ b/Library/Homebrew/cask/dsl/version.rb @@ -93,46 +93,68 @@ module Cask to_s == "latest" end + # @api public + sig { returns(T.self_type) } def major version { slice(MAJOR_MINOR_PATCH_REGEX, 1) } end + # @api public + sig { returns(T.self_type) } def minor version { slice(MAJOR_MINOR_PATCH_REGEX, 2) } end + # @api public + sig { returns(T.self_type) } def patch version { slice(MAJOR_MINOR_PATCH_REGEX, 3) } end + # @api public + sig { returns(T.self_type) } def major_minor version { [major, minor].reject(&:empty?).join(".") } end + # @api public + sig { returns(T.self_type) } def major_minor_patch version { [major, minor, patch].reject(&:empty?).join(".") } end + # @api public + sig { returns(T.self_type) } def minor_patch version { [minor, patch].reject(&:empty?).join(".") } end + # @api public + sig { returns(T.self_type) } def before_comma version { split(",", 2).first } end + # @api public + sig { returns(T.self_type) } def after_comma version { split(",", 2).second } end + # @api public + sig { returns(T.self_type) } def before_colon version { split(":", 2).first } end + # @api public + sig { returns(T.self_type) } def after_colon version { split(":", 2).second } end + # @api public + sig { returns(T.self_type) } def no_dividers version { gsub(DIVIDER_REGEX, "") } end diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index d8af5ed23b..70200abc56 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -555,26 +555,31 @@ class Version end alias eql? == + # @api public sig { returns(T.nilable(Token)) } def major tokens.first end + # @api public sig { returns(T.nilable(Token)) } def minor tokens.second end + # @api public sig { returns(T.nilable(Token)) } def patch tokens.third end + # @api public sig { returns(Version) } def major_minor Version.new([major, minor].compact.join(".")) end + # @api public sig { returns(Version) } def major_minor_patch Version.new([major, minor, patch].compact.join("."))