Class: U3d::UnityVersionComparator

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/u3d/unity_version_number.rb

Constant Summary collapse

RELEASE_LETTER_STRENGTH =
{ a: 1, b: 2, f: 3, p: 4 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ UnityVersionComparator

Returns a new instance of UnityVersionComparator.



64
65
66
67
# File 'lib/u3d/unity_version_number.rb', line 64

def initialize(version)
  version = UnityVersionNumber.new(version.to_s)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



50
51
52
# File 'lib/u3d/unity_version_number.rb', line 50

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/u3d/unity_version_number.rb', line 52

def <=>(other)
  comp = @version.parts[0] <=> other.version.parts[0]
  return comp if comp.nonzero?
  comp = @version.parts[1] <=> other.version.parts[1]
  return comp if comp.nonzero?
  comp = @version.parts[2] <=> other.version.parts[2]
  return comp if comp.nonzero?
  comp = RELEASE_LETTER_STRENGTH[@version.parts[3].to_sym] <=> RELEASE_LETTER_STRENGTH[other.version.parts[3].to_sym]
  return comp if comp.nonzero?
  return @version.parts[4] <=> other.version.parts[4]
end

#inspectObject



69
70
71
# File 'lib/u3d/unity_version_number.rb', line 69

def inspect
  @version
end