Class: Chewy::Runtime::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/chewy/runtime/version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



7
8
9
# File 'lib/chewy/runtime/version.rb', line 7

def initialize(version)
  @major, @minor, @patch = *(version.to_s.split('.', 3) + [0] * 3).first(3).map(&:to_i)
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



5
6
7
# File 'lib/chewy/runtime/version.rb', line 5

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



5
6
7
# File 'lib/chewy/runtime/version.rb', line 5

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



5
6
7
# File 'lib/chewy/runtime/version.rb', line 5

def patch
  @patch
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/chewy/runtime/version.rb', line 15

def <=>(other)
  other = self.class.new(other) unless other.is_a?(self.class)
  [
    major <=> other.major,
    minor <=> other.minor,
    patch <=> other.patch
  ].detect(&:nonzero?) || 0
end

#to_sObject



11
12
13
# File 'lib/chewy/runtime/version.rb', line 11

def to_s
  [major, minor, patch].join('.')
end