Class: Unwrappr::GemVersion
- Inherits:
-
Object
- Object
- Unwrappr::GemVersion
- 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
-
#hotfix ⇒ Object
readonly
Returns the value of attribute hotfix.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #hotfix_difference?(other) ⇒ Boolean
-
#initialize(version_string) ⇒ GemVersion
constructor
A new instance of GemVersion.
- #major_difference?(other) ⇒ Boolean
- #minor_difference?(other) ⇒ Boolean
- #patch_difference?(other) ⇒ Boolean
- #to_s ⇒ Object
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
#hotfix ⇒ Object (readonly)
Returns the value of attribute hotfix.
19 20 21 |
# File 'lib/unwrappr/gem_version.rb', line 19 def hotfix @hotfix end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
19 20 21 |
# File 'lib/unwrappr/gem_version.rb', line 19 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
19 20 21 |
# File 'lib/unwrappr/gem_version.rb', line 19 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
19 20 21 |
# File 'lib/unwrappr/gem_version.rb', line 19 def patch @patch end |
#version ⇒ Object (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
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
21 22 23 |
# File 'lib/unwrappr/gem_version.rb', line 21 def major_difference?(other) (major != other.major) end |
#minor_difference?(other) ⇒ 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
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_s ⇒ Object
47 48 49 |
# File 'lib/unwrappr/gem_version.rb', line 47 def to_s @version_string end |