Class: Fiveruns::Tuneup::Version

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

Overview

A class for describing the current version of a library. The version consists of three parts: the major number, the minor number, and the tiny (or patch) number.

Constant Summary collapse

MAJOR =
0
MINOR =
8
TINY =
20
CURRENT =

The current version as a Version instance

new(MAJOR, MINOR, TINY)
STRING =

The current version as a String

CURRENT.to_s

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, tiny) ⇒ Version

Create a new Version object with the given components.



51
52
53
# File 'lib/fiveruns/tuneup/version.rb', line 51

def initialize(major, minor, tiny)
  @major, @minor, @tiny = major, minor, tiny
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



48
49
50
# File 'lib/fiveruns/tuneup/version.rb', line 48

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



48
49
50
# File 'lib/fiveruns/tuneup/version.rb', line 48

def minor
  @minor
end

#tinyObject (readonly)

Returns the value of attribute tiny.



48
49
50
# File 'lib/fiveruns/tuneup/version.rb', line 48

def tiny
  @tiny
end

Class Method Details

.[](major, minor, tiny) ⇒ Object

A convenience method for instantiating a new Version instance with the given major, minor, and tiny components.



37
38
39
# File 'lib/fiveruns/tuneup/version.rb', line 37

def self.[](major, minor, tiny)
  new(major, minor, tiny)
end

.railsObject



41
42
43
44
45
46
# File 'lib/fiveruns/tuneup/version.rb', line 41

def self.rails
  @rails ||= begin
    # handle ::Rails::VERSION not being set
    Version.new(::Rails::VERSION::MAJOR, ::Rails::VERSION::MINOR, ::Rails::VERSION::TINY) rescue Version.new(0,0,0)
  end
end

Instance Method Details

#<=>(version) ⇒ Object

Compare this version to the given version object.



56
57
58
# File 'lib/fiveruns/tuneup/version.rb', line 56

def <=>(version)
  to_i <=> version.to_i
end

#to_aObject



72
73
74
# File 'lib/fiveruns/tuneup/version.rb', line 72

def to_a
  [@major, @minor, @tiny]
end

#to_iObject

Converts this version to a canonical integer that may be compared against other version objects.



68
69
70
# File 'lib/fiveruns/tuneup/version.rb', line 68

def to_i
  @to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
end

#to_sObject

Converts this version object to a string, where each of the three version components are joined by the ‘.’ character. E.g., 2.0.0.



62
63
64
# File 'lib/fiveruns/tuneup/version.rb', line 62

def to_s
  @to_s ||= [@major, @minor, @tiny].join(".")
end