Class: NewRelic::VersionNumber
- Inherits:
-
Object
- Object
- NewRelic::VersionNumber
- Includes:
- Comparable
- Defined in:
- lib/new_relic/version.rb
Overview
Helper class for managing version comparisons
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(version_string) ⇒ VersionNumber
constructor
A new instance of VersionNumber.
- #major_version ⇒ Object
- #minor_version ⇒ Object
- #tiny_version ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version_string) ⇒ VersionNumber
Returns a new instance of VersionNumber.
30 31 32 33 |
# File 'lib/new_relic/version.rb', line 30 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
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
28 29 30 |
# File 'lib/new_relic/version.rb', line 28 def parts @parts end |
Instance Method Details
#<=>(other) ⇒ Object
38 39 40 41 |
# File 'lib/new_relic/version.rb', line 38 def <=>(other) other = self.class.new(other) if other.is_a? String self.class.compare(self.parts, other.parts) end |
#eql?(other) ⇒ Boolean
51 52 53 |
# File 'lib/new_relic/version.rb', line 51 def eql? other (self <=> other) == 0 end |
#hash ⇒ Object
47 48 49 |
# File 'lib/new_relic/version.rb', line 47 def hash @parts.hash end |
#major_version ⇒ Object
34 |
# File 'lib/new_relic/version.rb', line 34 def major_version; @parts[0]; end |
#minor_version ⇒ Object
35 |
# File 'lib/new_relic/version.rb', line 35 def minor_version; @parts[1]; end |
#tiny_version ⇒ Object
36 |
# File 'lib/new_relic/version.rb', line 36 def tiny_version; @parts[2]; end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/new_relic/version.rb', line 43 def to_s @parts.join(".") end |