Class: Librarian::Manifest::PreReleaseVersion
- Inherits:
-
Object
- Object
- Librarian::Manifest::PreReleaseVersion
- Includes:
- Comparable
- Defined in:
- lib/librarian/puppet/extension.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Class Method Summary collapse
-
.compare_components(this_id, other_id) ⇒ Object
Compares pre-release component ids using Semver 2.0.0 spec.
-
.parse(prerelease) ⇒ Object
Parses pre-release components ‘a.b.c` into an array “[a,b,c]` Converts numeric components into
Integer
.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(prerelease) ⇒ PreReleaseVersion
constructor
A new instance of PreReleaseVersion.
- #to_s ⇒ Object
Constructor Details
#initialize(prerelease) ⇒ PreReleaseVersion
Returns a new instance of PreReleaseVersion.
140 141 142 143 |
# File 'lib/librarian/puppet/extension.rb', line 140 def initialize(prerelease) @prerelease = prerelease @components = PreReleaseVersion.parse(prerelease) end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
138 139 140 |
# File 'lib/librarian/puppet/extension.rb', line 138 def components @components end |
Class Method Details
.compare_components(this_id, other_id) ⇒ Object
Compares pre-release component ids using Semver 2.0.0 spec
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/librarian/puppet/extension.rb', line 112 def self.compare_components(this_id,other_id) case # Strings have higher precedence than numbers when (this_id.is_a?(Integer) and other_id.is_a?(String)) -1 when (this_id.is_a?(String) and other_id.is_a?(Integer)) 1 else this_id <=> other_id end end |
.parse(prerelease) ⇒ Object
Parses pre-release components ‘a.b.c` into an array “[a,b,c]` Converts numeric components into Integer
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/librarian/puppet/extension.rb', line 125 def self.parse(prerelease) if prerelease.nil? [] else prerelease.split('.').collect do |id| id = Integer(id) if /^[0-9]+$/ =~ id id end end end |
Instance Method Details
#<=>(other) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/librarian/puppet/extension.rb', line 149 def <=>(other) # null-fill zip array to prevent loss of components z = Array.new([components.length,other.components.length]) # Compare each component against the other comp = z.zip(components,other.components).collect do |ids| case # All components being equal, the version with more of them takes precedence when ids[1].nil? # Self has less elements, other wins -1 when ids[2].nil? # Other has less elements, self wins 1 else PreReleaseVersion.compare_components(ids[1],ids[2]) end end # Chose the first non-zero comparison or return 0 comp.delete_if {|c| c == 0}[0] || 0 end |
#to_s ⇒ Object
145 146 147 |
# File 'lib/librarian/puppet/extension.rb', line 145 def to_s @prerelease end |