Method: RunLoop::Version.compare

Defined in:
lib/run_loop/version.rb

.compare(a, b) ⇒ Integer

Compare version a to version b.

Examples:

compare Version.new(0.10.0), Version.new(0.9.0)  =>  1
compare Version.new(0.9.0),  Version.new(0.10.0) => -1
compare Version.new(0.9.0),  Version.new(0.9.0)  =>  0

Returns:

  • (Integer)

    an integer ‘(-1, 1)`



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/run_loop/version.rb', line 178

def self.compare(a, b)

  if a.major != b.major
    return a.major.to_i > b.major.to_i ? 1 : -1
  end

  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

  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 && (!a.pre_version) && b.pre_version
  return 1 if a.pre_version && b.pre && (!b.pre_version)

  return -1 if a.pre && (!b.pre)
  return 1 if (!a.pre) && b.pre

  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
end