Class: Unwrappr::GemVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/unwrappr/gem_version.rb

Overview

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/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_string) ⇒ GemVersion

Returns a new instance of GemVersion.



10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#hotfixObject (readonly)

Returns the value of attribute hotfix.



19
20
21
# File 'lib/unwrappr/gem_version.rb', line 19

def hotfix
  @hotfix
end

#majorObject (readonly)

Returns the value of attribute major.



19
20
21
# File 'lib/unwrappr/gem_version.rb', line 19

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



19
20
21
# File 'lib/unwrappr/gem_version.rb', line 19

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



19
20
21
# File 'lib/unwrappr/gem_version.rb', line 19

def patch
  @patch
end

#versionObject (readonly)

Returns the value of attribute version.



19
20
21
# File 'lib/unwrappr/gem_version.rb', line 19

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



43
44
45
# File 'lib/unwrappr/gem_version.rb', line 43

def <=>(other)
  @version <=> other.version
end

#hotfix_difference?(other) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# 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) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/unwrappr/gem_version.rb', line 21

def major_difference?(other)
  (major != other.major)
end

#minor_difference?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/unwrappr/gem_version.rb', line 25

def minor_difference?(other)
  (major == other.major) &&
    (minor != other.minor)
end

#patch_difference?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/unwrappr/gem_version.rb', line 30

def patch_difference?(other)
  (major == other.major) &&
    (minor == other.minor) &&
    (patch != other.patch)
end

#to_sObject



47
48
49
# File 'lib/unwrappr/gem_version.rb', line 47

def to_s
  @version_string
end