Sha256: 1df587dfccdfa735d0135dd840646bb8cf823b6f0fad27c5bae517eddfbb4c52

Contents?: true

Size: 855 Bytes

Versions: 12

Compression:

Stored size: 855 Bytes

Contents

# frozen_string_literal: true

class ImageOptim
  class BinResolver
    # Allows comparision of simple versions, only numbers separated by dots are
    # taken into account
    class SimpleVersion
      include Comparable

      # Numbers extracted from version string
      attr_reader :parts

      # Initialize with a string or an object convertible to string
      #
      #    SimpleVersion.new('2.0.1') <=> SimpleVersion.new(2)
      def initialize(str)
        @str = String(str)
        @parts = @str.split('.').map(&:to_i).reverse.drop_while(&:zero?).reverse
      end

      # Returns original version string
      def to_s
        @str
      end

      # Compare version parts of self with other
      def <=>(other)
        other = self.class.new(other) unless other.is_a?(self.class)
        parts <=> other.parts
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
image_optim-0.31.4 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.31.3 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.31.2 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.31.1 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.31.0 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.30.0 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.29.0 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.28.0 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.27.1 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.27.0 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.26.5 lib/image_optim/bin_resolver/simple_version.rb
image_optim-0.26.4 lib/image_optim/bin_resolver/simple_version.rb