Class: ImageOptim::BinResolver::SimpleVersion
- Inherits:
-
Object
- Object
- ImageOptim::BinResolver::SimpleVersion
- 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
-
#parts ⇒ Object
readonly
Numbers extracted from version string.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare version parts of self with other.
-
#initialize(str) ⇒ SimpleVersion
constructor
Initialize with a string or an object convertible to string.
-
#to_s ⇒ Object
Returns original version string.
Constructor Details
#initialize(str) ⇒ SimpleVersion
Initialize with a string or an object convertible to string
SimpleVersion.new('2.0.1') <=> SimpleVersion.new(2)
16 17 18 19 |
# 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 |
Instance Attribute Details
#parts ⇒ Object (readonly)
Numbers extracted from version string
11 12 13 |
# File 'lib/image_optim/bin_resolver/simple_version.rb', line 11 def parts @parts end |
Instance Method Details
#<=>(other) ⇒ Object
Compare version parts of self with other
27 28 29 30 |
# 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 ⇒ Object
Returns original version string
22 23 24 |
# File 'lib/image_optim/bin_resolver/simple_version.rb', line 22 def to_s @str end |