class Puppet::Util::Package::Version::PIP_VERSION
Constants
- VERSION_PATTERN
Attributes
key[R]
Public Class Methods
compare(version_a, version_b)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 45 def self.compare(version_a, version_b) 46 version_a = parse(version_a) unless version_a.is_a?(self) 47 version_b = parse(version_b) unless version_b.is_a?(self) 48 49 version_a <=> version_b 50 end
new(matched)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 80 def initialize(matched) 81 @epoch_data = matched[:epoch].to_i 82 @release_data = matched[:release].split('.').map(&:to_i) if matched[:release] 83 @pre_data = parse_letter_version(matched[:pre_l], matched[:pre_n]) if matched[:pre_l] || matched[:pre_n] 84 @post_data = parse_letter_version(matched[:post_l], matched[:post_n1] || matched[:post_n2]) if matched[:post_l] || matched[:post_n1] || matched[:post_n2] 85 @dev_data = parse_letter_version(matched[:dev_l], matched[:dev_n]) if matched[:dev_l] || matched[:dev_n] 86 @local_data = parse_local_version(matched[:local]) if matched[:local] 87 88 @key = compose_key(@epoch_data, @release_data, @pre_data, @post_data, @dev_data, @local_data) 89 end
parse(version)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 36 def self.parse(version) 37 raise ValidationFailure, version.to_s unless version.is_a? String 38 39 matched = version.match(Regexp.new(("^\\s*") + VERSION_PATTERN + ("\\s*$"), Regexp::EXTENDED | Regexp::MULTILINE | Regexp::IGNORECASE)) 40 raise ValidationFailure, version unless matched 41 42 new(matched) 43 end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 71 def <=>(other) 72 raise ValidationFailure, other.to_s unless other.is_a?(self.class) 73 compare(key, other.key) 74 end
eql?(other)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 66 def eql?(other) 67 other.is_a?(self.class) && key.eql?(other.key) 68 end
Also aliased as: ==
to_s()
click to toggle source
# File lib/puppet/util/package/version/pip.rb 52 def to_s 53 parts = [] 54 55 parts.push("#{@epoch_data}!") if @epoch_data && @epoch_data != 0 56 parts.push(@release_data.join(".")) if @release_data 57 parts.push(@pre_data.join) if @pre_data 58 parts.push(".post#{@post_data[1]}") if @post_data 59 parts.push(".dev#{@dev_data[1]}") if @dev_data 60 parts.push("+#{@local_data.join(".")}") if @local_data 61 62 parts.join 63 end
Also aliased as: inspect
Private Instance Methods
compare(this, other)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 143 def compare(this, other) 144 if (this.is_a? Array) && (other.is_a? Array) 145 this << -Float::INFINITY if this.length < other.length 146 other << -Float::INFINITY if this.length > other.length 147 148 this.each_with_index do |element, index| 149 return compare(element, other.at(index)) if element != other.at(index) 150 end 151 elsif (this.is_a? Array) && !(other.is_a? Array) 152 raise Puppet::Error, 'Cannot compare #{this} (Array) with #{other} (#{other.class}). Only ±Float::INFINITY accepted.' unless other.abs == Float::INFINITY 153 return other == -Float::INFINITY ? 1 : -1 154 elsif !(this.is_a? Array) && (other.is_a? Array) 155 raise Puppet::Error, 'Cannot compare #{this} (#{this.class}) with #{other} (Array). Only ±Float::INFINITY accepted.' unless this.abs == Float::INFINITY 156 return this == -Float::INFINITY ? -1 : 1 157 end 158 this <=> other 159 end
compose_key(epoch, release, pre, post, dev, local)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 116 def compose_key(epoch, release, pre, post, dev, local) 117 release_key = release.reverse 118 release_key.each_with_index do |element, index| 119 break unless element == 0 120 release_key.delete_at(index) unless release_key.at(index + 1) != 0 121 end 122 release_key.reverse! 123 124 if !pre && !post && dev 125 pre_key = -Float::INFINITY 126 else 127 pre_key = pre || Float::INFINITY 128 end 129 130 post_key = post || -Float::INFINITY 131 132 dev_key = dev || Float::INFINITY 133 134 if !local 135 local_key = [[-Float::INFINITY, ""]] 136 else 137 local_key = local.map{|i| (i.is_a? Integer) ? [i, ""] : [-Float::INFINITY, i]} 138 end 139 140 [epoch, release_key, pre_key, post_key, dev_key, local_key] 141 end
parse_letter_version(letter, number)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 91 def parse_letter_version(letter, number) 92 if letter 93 number = 0 if !number 94 letter.downcase! 95 96 if letter == "alpha" 97 letter = "a" 98 elsif letter == "beta" 99 letter = "b" 100 elsif ["c", "pre", "preview"].include?(letter) 101 letter = "rc" 102 elsif ["rev", "r"].include?(letter) 103 letter = "post" 104 end 105 106 return [letter, number.to_i] 107 end 108 109 ["post", number.to_i] if !letter && number 110 end
parse_local_version(local_version)
click to toggle source
# File lib/puppet/util/package/version/pip.rb 112 def parse_local_version(local_version) 113 local_version.split(/[\\._-]/).map{|part| part =~ /[0-9]+/ && part !~ /[a-zA-Z]+/ ? part.to_i : part.downcase} if local_version 114 end