Class: ImageOptim::BinResolver::SimpleVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/image_optim/bin_resolver/simple_version.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ SimpleVersion

Returns a new instance of SimpleVersion.



9
10
11
12
# File 'lib/image_optim/bin_resolver/simple_version.rb', line 9

def initialize(str)
  @str = String(str)
  @parts = @str.split('.').map(&:to_i).reverse.drop_while(&:zero?).reverse
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



8
9
10
# File 'lib/image_optim/bin_resolver/simple_version.rb', line 8

def parts
  @parts
end

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
21
# File 'lib/image_optim/bin_resolver/simple_version.rb', line 18

def <=>(other)
  other = self.class.new(other) unless other.is_a?(self.class)
  parts <=> other.parts
end

#to_sObject



14
15
16
# File 'lib/image_optim/bin_resolver/simple_version.rb', line 14

def to_s
  @str
end