Class: Dependabot::Nuget::Version
- Inherits:
-
Gem::Version
- Object
- Gem::Version
- Dependabot::Nuget::Version
- Defined in:
- lib/dependabot/nuget/version.rb
Constant Summary collapse
- VERSION_PATTERN =
Gem::Version::VERSION_PATTERN + '(\+[0-9a-zA-Z\-.]+)?'
- ANCHORED_VERSION_PATTERN =
/\A\s*(#{VERSION_PATTERN})?\s*\z/
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#compare_dot_separated_part(lhs, rhs) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity.
-
#compare_prerelease_part(other) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- #compare_release(other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
-
#inspect ⇒ Object
:nodoc:.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
22 23 24 25 26 27 |
# File 'lib/dependabot/nuget/version.rb', line 22 def initialize(version) version = version.to_s.split("+").first || "" @version_string = version super end |
Class Method Details
.correct?(version) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/dependabot/nuget/version.rb', line 16 def self.correct?(version) return false if version.nil? version.to_s.match?(ANCHORED_VERSION_PATTERN) end |
Instance Method Details
#<=>(other) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/dependabot/nuget/version.rb', line 37 def <=>(other) version_comparison = compare_release(other) return version_comparison unless version_comparison.zero? compare_prerelease_part(other) end |
#compare_dot_separated_part(lhs, rhs) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity
84 85 86 87 88 89 90 91 |
# File 'lib/dependabot/nuget/version.rb', line 84 def compare_dot_separated_part(lhs, rhs) return -1 if lhs.nil? return 1 if rhs.nil? return lhs.to_i <=> rhs.to_i if lhs.match?(/^\d+$/) && rhs.match?(/^\d+$/) lhs.upcase <=> rhs.upcase end |
#compare_prerelease_part(other) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dependabot/nuget/version.rb', line 52 def compare_prerelease_part(other) release_str = @version_string.split("-").first || "" prerelease_string = @version_string. sub(release_str, ""). sub("-", "") prerelease_string = nil if prerelease_string == "" other_release_str = other.to_s.split("-").first || "" other_prerelease_string = other.to_s. sub(other_release_str, ""). sub("-", "") other_prerelease_string = nil if other_prerelease_string == "" return -1 if prerelease_string && !other_prerelease_string return 1 if !prerelease_string && other_prerelease_string return 0 if !prerelease_string && !other_prerelease_string split_prerelease_string = prerelease_string.split(".") other_split_prerelease_string = other_prerelease_string.split(".") length = [split_prerelease_string.length, other_split_prerelease_string.length].max - 1 (0..length).to_a.each do |index| lhs = split_prerelease_string[index] rhs = other_split_prerelease_string[index] result = compare_dot_separated_part(lhs, rhs) return result unless result.zero? end 0 end |
#compare_release(other) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/dependabot/nuget/version.rb', line 44 def compare_release(other) release_str = @version_string.split("-").first || "" other_release_str = other.to_s.split("-").first || "" Gem::Version.new(release_str).<=>(Gem::Version.new(other_release_str)) end |
#inspect ⇒ Object
:nodoc:
33 34 35 |
# File 'lib/dependabot/nuget/version.rb', line 33 def inspect # :nodoc: "#<#{self.class} #{@version_string}>" end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/dependabot/nuget/version.rb', line 29 def to_s @version_string end |