semi_semantic 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/semi_semantic/version_segment.rb +36 -6
- metadata +2 -2
@@ -26,7 +26,15 @@ module SemiSemantic
|
|
26
26
|
# Construction can throw ArgumentError, but does no parsing or type-conversion
|
27
27
|
def initialize(components)
|
28
28
|
raise ArgumentError.new 'Invalid Version Components: nil' if components.nil?
|
29
|
-
raise ArgumentError.new
|
29
|
+
raise ArgumentError.new 'Invalid Version Components: Empty Array' if components.empty?
|
30
|
+
components.each do |component|
|
31
|
+
unless component.is_a?(String) || component.is_a?(Integer)
|
32
|
+
raise ArgumentError.new "Invalid Version Component Type: #{component.class}"
|
33
|
+
end
|
34
|
+
if component == ''
|
35
|
+
raise ArgumentError.new 'Invalid Version Component: Empty String'
|
36
|
+
end
|
37
|
+
end
|
30
38
|
@components = components
|
31
39
|
end
|
32
40
|
|
@@ -34,17 +42,17 @@ module SemiSemantic
|
|
34
42
|
a = @components
|
35
43
|
b = other.components
|
36
44
|
if a.size > b.size
|
37
|
-
comparison = a[0...b.size]
|
45
|
+
comparison = compare_arrays(a[0...b.size], b)
|
38
46
|
return comparison unless comparison == 0
|
39
|
-
a[b.size..-1]
|
47
|
+
return 1 unless is_all_zeros?(a[b.size..-1])
|
40
48
|
0
|
41
49
|
elsif a.size < b.size
|
42
|
-
comparison = a
|
50
|
+
comparison = compare_arrays(a, b[0...a.size])
|
43
51
|
return comparison unless comparison == 0
|
44
|
-
b[a.size..-1]
|
52
|
+
return -1 unless is_all_zeros?(b[a.size..-1])
|
45
53
|
0
|
46
54
|
else
|
47
|
-
a
|
55
|
+
compare_arrays(a, b)
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|
@@ -84,5 +92,27 @@ module SemiSemantic
|
|
84
92
|
def to_s
|
85
93
|
@components.join('.')
|
86
94
|
end
|
95
|
+
|
96
|
+
private
|
97
|
+
# a & b must have the same length
|
98
|
+
def compare_arrays(a, b)
|
99
|
+
a.each_with_index do |v1, i|
|
100
|
+
v2 = b[i]
|
101
|
+
if v1.is_a?(String) && v2.is_a?(Integer)
|
102
|
+
return 1
|
103
|
+
elsif v1.is_a?(Integer) && v2.is_a?(String)
|
104
|
+
return -1
|
105
|
+
end
|
106
|
+
comparison = v1 <=> v2
|
107
|
+
unless comparison == 0
|
108
|
+
return comparison
|
109
|
+
end
|
110
|
+
end
|
111
|
+
0
|
112
|
+
end
|
113
|
+
|
114
|
+
def is_all_zeros?(array)
|
115
|
+
array.all? { |e| e == 0 }
|
116
|
+
end
|
87
117
|
end
|
88
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semi_semantic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: 1.0.0.rc1
|
46
46
|
description: ! 'Semi Semantic
|
47
47
|
|
48
|
-
|
48
|
+
ca37a8'
|
49
49
|
email: support@cloudfoundry.com
|
50
50
|
executables: []
|
51
51
|
extensions: []
|