class Librarian::Manifest::PreReleaseVersion
Attributes
components[R]
Public Class Methods
compare_components(this_id,other_id)
click to toggle source
Compares pre-release component ids using Semver 2.0.0 spec
# File lib/librarian/manifest/pre_release_version.rb, line 7 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
new(prerelease)
click to toggle source
# File lib/librarian/manifest/pre_release_version.rb, line 35 def initialize(prerelease) @prerelease = prerelease @components = PreReleaseVersion.parse(prerelease) end
parse(prerelease)
click to toggle source
Parses pre-release components ‘a.b.c` into an array “[a,b,c]` Converts numeric components into Integer
# File lib/librarian/manifest/pre_release_version.rb, line 20 def self.parse(prerelease) if prerelease.nil? [] else prerelease.split('.').collect do |id| id = Integer(id) if /^[0-9]+$/ =~ id id end end end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/librarian/manifest/pre_release_version.rb, line 44 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()
click to toggle source
# File lib/librarian/manifest/pre_release_version.rb, line 40 def to_s @prerelease end