class ImageOptim::BinResolver::SimpleVersion

Allows comparision of simple versions, only numbers separated by dots are taken into account

Attributes

parts[R]

Numbers extracted from version string

Public Class Methods

new(str) click to toggle source

Initialize with a string or an object convertible to string

SimpleVersion.new('2.0.1') <=> SimpleVersion.new(2)
# File lib/image_optim/bin_resolver/simple_version.rb, line 16
def initialize(str)
  @str = String(str)
  @parts = @str.split('.').map(&:to_i).reverse.drop_while(&:zero?).reverse
end

Public Instance Methods

<=>(other) click to toggle source

Compare version parts of self with other

# File lib/image_optim/bin_resolver/simple_version.rb, line 27
def <=>(other)
  other = self.class.new(other) unless other.is_a?(self.class)
  parts <=> other.parts
end
to_s() click to toggle source

Returns original version string

# File lib/image_optim/bin_resolver/simple_version.rb, line 22
def to_s
  @str
end