Class: Hbc::DSL::Version

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

Constant Summary collapse

DIVIDERS =
{
  "." => :dots,
  "-" => :hyphens,
  "_" => :underscores,
  "/" => :slashes,
}.freeze
DIVIDER_REGEX =
/(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/
MAJOR_MINOR_PATCH_REGEX =
/^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#chuzzle, #f, #strip_prefix

Constructor Details

#initialize(raw_version) ⇒ Version

Returns a new instance of Version



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

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



56
57
58
# File 'Library/Homebrew/cask/lib/hbc/dsl/version.rb', line 56

def raw_version
  @raw_version
end

Instance Method Details

#after_colonObject



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

def after_colon
  version { split(":", 2)[1] }
end

#after_commaObject



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

def after_comma
  version { split(",", 2)[1] }
end

#before_colonObject



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

def before_colon
  version { split(":", 2)[0] }
end

#before_commaObject



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

def before_comma
  version { split(",", 2)[0] }
end

#latest?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'Library/Homebrew/cask/lib/hbc/dsl/version.rb', line 63

def latest?
  to_s == "latest"
end

#majorObject



67
68
69
# File 'Library/Homebrew/cask/lib/hbc/dsl/version.rb', line 67

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

#major_minorObject



79
80
81
# File 'Library/Homebrew/cask/lib/hbc/dsl/version.rb', line 79

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

#major_minor_patchObject



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

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

#minorObject



71
72
73
# File 'Library/Homebrew/cask/lib/hbc/dsl/version.rb', line 71

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

#no_dividersObject



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

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

#patchObject



75
76
77
# File 'Library/Homebrew/cask/lib/hbc/dsl/version.rb', line 75

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