lib/run_loop/version.rb in run_loop-2.4.1 vs lib/run_loop/version.rb in run_loop-2.5.0
- old
+ new
@@ -1,7 +1,7 @@
module RunLoop
- VERSION = "2.4.1"
+ VERSION = "2.5.0"
# A model of a software release version that can be used to compare two versions.
#
# Calabash and RunLoop try very hard to comply with Semantic Versioning rules.
# However, the semantic versioning spec is incompatible with RubyGem's patterns
@@ -100,11 +100,19 @@
hash == other.hash
end
# The hash method for this instance.
def hash
- to_s.hash
+ str = [major, minor, patch].map do |str|
+ str ? str : "0"
+ end.join(".")
+
+ if pre
+ str = "#{str}.#{pre}"
+ end
+
+ str.hash
end
# Compare this version to another for equality.
# @param [Version] other the version to compare against
# @return [Boolean] true if this Version is the same as `other`
@@ -156,28 +164,32 @@
#
# @return [Integer] an integer `(-1, 1)`
def self.compare(a, b)
if a.major != b.major
- return a.major > b.major ? 1 : -1
+ return a.major.to_i > b.major.to_i ? 1 : -1
end
- if a.minor != b.minor
- return a.minor.to_i > b.minor.to_i ? 1 : -1
+ a_minor = a.minor ? a.minor.to_i : 0
+ b_minor = b.minor ? b.minor.to_i : 0
+ if a_minor != b_minor
+ return a_minor > b_minor.to_i ? 1 : -1
end
- if a.patch != b.patch
- return a.patch.to_i > b.patch.to_i ? 1 : -1
+ a_patch = a.patch ? a.patch.to_i : 0
+ b_patch = b.patch ? b.patch.to_i : 0
+ if a_patch != b_patch
+ return a_patch.to_i > b_patch.to_i ? 1 : -1
end
- return -1 if a.pre and (not a.pre_version) and b.pre_version
- return 1 if a.pre_version and b.pre and (not b.pre_version)
+ return -1 if a.pre && (!a.pre_version) && b.pre_version
+ return 1 if a.pre_version && b.pre && (!b.pre_version)
- return -1 if a.pre and (not b.pre)
- return 1 if (not a.pre) and b.pre
+ return -1 if a.pre && (!b.pre)
+ return 1 if (!a.pre) && b.pre
- return -1 if a.pre_version and (not b.pre_version)
- return 1 if (not a.pre_version) and b.pre_version
+ return -1 if a.pre_version && (!b.pre_version)
+ return 1 if (!a.pre_version) && b.pre_version
if a.pre_version != b.pre_version
return a.pre_version.to_i > b.pre_version.to_i ? 1 : -1
end
0