class Unwrappr::GemVersion

Represents the version of a gem. Helps in comparing two versions to identify differences and extracting the major, minor and patch components that make up semantic versioning. semver.org/

Attributes

hotfix[R]
major[R]
minor[R]
patch[R]
version[R]

Public Class Methods

new(version_string) click to toggle source
# File lib/unwrappr/gem_version.rb, line 10
def initialize(version_string)
  @version_string = version_string
  @version = Gem::Version.create(version_string)
  @major = segment(0)
  @minor = segment(1)
  @patch = segment(2)
  @hotfix = segment(3)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/unwrappr/gem_version.rb, line 43
def <=>(other)
  @version <=> other.version
end
hotfix_difference?(other) click to toggle source
# File lib/unwrappr/gem_version.rb, line 36
def hotfix_difference?(other)
  (major == other.major) &&
    (minor == other.minor) &&
    (patch == other.patch) &&
    (hotfix != other.hotfix)
end
major_difference?(other) click to toggle source
# File lib/unwrappr/gem_version.rb, line 21
def major_difference?(other)
  (major != other.major)
end
minor_difference?(other) click to toggle source
# File lib/unwrappr/gem_version.rb, line 25
def minor_difference?(other)
  (major == other.major) &&
    (minor != other.minor)
end
patch_difference?(other) click to toggle source
# File lib/unwrappr/gem_version.rb, line 30
def patch_difference?(other)
  (major == other.major) &&
    (minor == other.minor) &&
    (patch != other.patch)
end
to_s() click to toggle source
# File lib/unwrappr/gem_version.rb, line 47
def to_s
  @version_string
end

Private Instance Methods

segment(index) click to toggle source
# File lib/unwrappr/gem_version.rb, line 53
def segment(index)
  segment = @version.canonical_segments[index] || 0
  (segment.is_a?(Numeric) ? segment : nil)
end