Module: VersionCompareLittle

Defined in:
lib/version_compare_little/core.rb,
lib/version_compare_little/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.compare(ope_1, operator, ope_2) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/version_compare_little/core.rb', line 3

def self.compare(ope_1, operator, ope_2)
  ope_arr_1 = ope_1.split('.')
  ope_arr_2 = ope_2.split('.')
  n = return_bigger(ope_arr_1.length, ope_arr_2.length)
  res = false
  n.times do |idx|
    res = eval "#{ope_arr_1[idx].to_i} #{operator} #{ope_arr_2[idx].to_i}"
    break if res
  end
  res
end

.return_bigger(ope1, ope2) ⇒ Object



15
16
17
18
19
# File 'lib/version_compare_little/core.rb', line 15

def self.return_bigger(ope1, ope2)
  return ope1 if ope1 > ope2
  return ope2 if ope2 > ope1
  return ope1 if ope1 = ope2
end