Class: NewRelic::VersionNumber

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

Overview

Helper class for managing version comparisons

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_string) ⇒ VersionNumber

Returns a new instance of VersionNumber.



15
16
17
18
# File 'lib/new_relic/version.rb', line 15

def initialize(version_string)
  version_string ||= '1.0.0'
  @parts = version_string.split('.').map{|n| n =~ /^\d+$/ ? n.to_i : n}
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



13
14
15
# File 'lib/new_relic/version.rb', line 13

def parts
  @parts
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
# File 'lib/new_relic/version.rb', line 23

def <=>(other)
  other = self.class.new(other) if other.is_a? String
  self.class.compare(self.parts, other.parts)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/new_relic/version.rb', line 36

def eql? other
  (self <=> other) == 0
end

#hashObject



32
33
34
# File 'lib/new_relic/version.rb', line 32

def hash
  @parts.hash
end

#major_versionObject



19
# File 'lib/new_relic/version.rb', line 19

def major_version; @parts[0]; end

#minor_versionObject



20
# File 'lib/new_relic/version.rb', line 20

def minor_version; @parts[1]; end

#tiny_versionObject



21
# File 'lib/new_relic/version.rb', line 21

def tiny_version; @parts[2]; end

#to_sObject



28
29
30
# File 'lib/new_relic/version.rb', line 28

def to_s
  @parts.join(".")
end