Module: Bosh::Cli::VersionCalc

Instance Method Summary collapse

Instance Method Details

#major_version(v) ⇒ Object



33
34
35
# File 'lib/cli/version_calc.rb', line 33

def major_version(v)
  components(v)[0].to_i
end

#minor_version(v) ⇒ Object



37
38
39
# File 'lib/cli/version_calc.rb', line 37

def minor_version(v)
  components(v)[1].to_i
end

#version_cmp(v1 = "0", v2 = "0") ⇒ Object

Returns 0 if two versions are the same, 1 if v1 > v2 -1 if v1 < v2



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cli/version_calc.rb', line 9

def version_cmp(v1 = "0", v2 = "0")
  vp1 = components(v1)
  vp2 = components(v2)

  [vp1.size, vp2.size].max.times do |i|
    result = vp1[i].to_i <=> vp2[i].to_i
    return result unless result == 0
  end

  0
end

#version_greater(v1, v2) ⇒ Object



21
22
23
# File 'lib/cli/version_calc.rb', line 21

def version_greater(v1, v2)
  version_cmp(v1, v2) > 0
end

#version_less(v1, v2) ⇒ Object



25
26
27
# File 'lib/cli/version_calc.rb', line 25

def version_less(v1, v2)
  version_cmp(v1, v2) < 0
end

#version_same(v1, v2) ⇒ Object



29
30
31
# File 'lib/cli/version_calc.rb', line 29

def version_same(v1, v2)
  version_cmp(v1, v2) == 0
end