Class: Hackle::Version
- Inherits:
-
Object
- Object
- Hackle::Version
- Includes:
- Comparable
- Defined in:
- lib/hackle/internal/model/version.rb
Constant Summary collapse
- VERSION_REGEX =
/^(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(\S+))?$/.freeze
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
- #core_version ⇒ CoreVersion readonly
- #prerelease ⇒ MetadataVersion readonly
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(core_version:, prerelease:, build:) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(core_version:, prerelease:, build:) ⇒ Version
Returns a new instance of Version.
21 22 23 24 25 |
# File 'lib/hackle/internal/model/version.rb', line 21 def initialize(core_version:, prerelease:, build:) @core_version = core_version @prerelease = prerelease @build = build end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
13 |
# File 'lib/hackle/internal/model/version.rb', line 13 attr_reader :core_version, :prerelease, :build |
#core_version ⇒ CoreVersion (readonly)
13 14 15 |
# File 'lib/hackle/internal/model/version.rb', line 13 def core_version @core_version end |
#prerelease ⇒ MetadataVersion (readonly)
13 |
# File 'lib/hackle/internal/model/version.rb', line 13 attr_reader :core_version, :prerelease, :build |
Class Method Details
.parse_or_nil(value) ⇒ Version?
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hackle/internal/model/version.rb', line 31 def self.parse_or_nil(value) return nil unless value.is_a?(String) match = VERSION_REGEX.match(value) return nil unless match core_version = CoreVersion.new(major: match[1].to_i, minor: (match[2] || 0).to_i, patch: (match[3] || 0).to_i) prerelease = MetadataVersion.parse(match[4]) build = MetadataVersion.parse(match[5]) new(core_version: core_version, prerelease: prerelease, build: build) end |
Instance Method Details
#<=>(other) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/hackle/internal/model/version.rb', line 43 def <=>(other) core_comparison = core_version <=> other.core_version return core_comparison unless core_comparison.zero? prerelease <=> other.prerelease end |
#==(other) ⇒ Object
50 51 52 |
# File 'lib/hackle/internal/model/version.rb', line 50 def ==(other) other.is_a?(Version) && (self <=> other).zero? end |
#to_s ⇒ Object
54 55 56 57 58 59 |
# File 'lib/hackle/internal/model/version.rb', line 54 def to_s str = core_version.to_s str += "-#{prerelease}" unless prerelease.empty? str += "+#{build}" unless build.empty? str end |