Sha256: 464cc0593d4ae4d8d2abb954ea9dfc48ae7022b366ea1a52e6ebb419dc31e15b

Contents?: true

Size: 493 Bytes

Versions: 5

Compression:

Stored size: 493 Bytes

Contents

# frozen_string_literal: true

module Friends
  module SemVerComparator
    SEPARATOR = "."
    NUMBER_REGEX = /\d+/.freeze

    def self.greater?(version_a, version_b)
      version_a.split(SEPARATOR).zip(version_b.split(SEPARATOR)) do |a, b|
        a_num = a&.[](NUMBER_REGEX)&.to_i
        b_num = b&.[](NUMBER_REGEX)&.to_i
        return false if a_num.nil?
        return true if b_num.nil? || a_num > b_num
        return false if a_num < b_num
      end

      false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
friends-0.55 lib/friends/sem_ver_comparator.rb
friends-0.54 lib/friends/sem_ver_comparator.rb
friends-0.53 lib/friends/sem_ver_comparator.rb
friends-0.52 lib/friends/sem_ver_comparator.rb
friends-0.51 lib/friends/sem_ver_comparator.rb