Class: Cask::DSL::Version

Inherits:
String
  • Object
show all
Defined in:
brew/Library/Homebrew/cask/dsl/version.rb

Constant Summary collapse

DIVIDERS =
{
  "." => :dots,
  "-" => :hyphens,
  "_" => :underscores,
}.freeze
DIVIDER_REGEX =
/(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/.freeze
MAJOR_MINOR_PATCH_REGEX =
/^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/.freeze
INVALID_CHARACTERS =
/[^0-9a-zA-Z\.\,\:\-\_]/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#chuzzle, #f, #undent

Constructor Details

#initialize(raw_version) ⇒ Version

Returns a new instance of Version



61
62
63
64
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 61

def initialize(raw_version)
  @raw_version = raw_version
  super(raw_version.to_s)
end

Instance Attribute Details

#raw_versionObject (readonly)

Returns the value of attribute raw_version



59
60
61
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 59

def raw_version
  @raw_version
end

Instance Method Details

#after_colonObject



123
124
125
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 123

def after_colon
  version { split(":", 2).second }
end

#after_commaObject



115
116
117
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 115

def after_comma
  version { split(",", 2).second }
end

#before_colonObject



119
120
121
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 119

def before_colon
  version { split(":", 2).first }
end

#before_commaObject



111
112
113
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 111

def before_comma
  version { split(",", 2).first }
end

#invalid_charactersObject



66
67
68
69
70
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 66

def invalid_characters
  return [] if latest?

  raw_version.scan(INVALID_CHARACTERS)
end

#latest?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 83

def latest?
  to_s == "latest"
end

#majorObject



87
88
89
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 87

def major
  version { slice(MAJOR_MINOR_PATCH_REGEX, 1) }
end

#major_minorObject



99
100
101
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 99

def major_minor
  version { [major, minor].reject(&:empty?).join(".") }
end

#major_minor_patchObject



103
104
105
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 103

def major_minor_patch
  version { [major, minor, patch].reject(&:empty?).join(".") }
end

#minorObject



91
92
93
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 91

def minor
  version { slice(MAJOR_MINOR_PATCH_REGEX, 2) }
end

#minor_patchObject



107
108
109
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 107

def minor_patch
  version { [minor, patch].reject(&:empty?).join(".") }
end

#no_dividersObject



127
128
129
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 127

def no_dividers
  version { gsub(DIVIDER_REGEX, "") }
end

#patchObject



95
96
97
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 95

def patch
  version { slice(MAJOR_MINOR_PATCH_REGEX, 3) }
end

#unstable?Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
80
81
# File 'brew/Library/Homebrew/cask/dsl/version.rb', line 72

def unstable?
  return false if latest?

  s = downcase.delete(".").gsub(/[^a-z\d]+/, "-")

  return true if s.match?(/(\d+|\b)(alpha|beta|preview|rc|dev|canary|snapshot)(\d+|\b)/i)
  return true if s.match?(/\A[a-z\d]+(\-\d+)*\-?(a|b|pre)(\d+|\b)/i)

  false
end