Class: Ore::Versions::Version

Inherits:
Gem::Version
  • Object
show all
Defined in:
lib/ore/versions/version.rb

Overview

Represents a standard three-number version.

See Also:

Direct Known Subclasses

VersionConstant, VersionFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, patch, build = nil) ⇒ Version

Creates a new version.

Parameters:

  • major (Integer, nil)

    The major version number.

  • minor (Integer, nil)

    The minor version number.

  • patch (Integer, nil)

    The patch version number.

  • build (Integer, nil) (defaults to: nil)

    (nil) The build version number.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ore/versions/version.rb', line 41

def initialize(major,minor,patch,build=nil)
  @major = (major || 0)
  @minor = (minor || 0)
  @patch = (patch || 0)
  @build = build

  numbers = [@major,@minor,@patch]
  numbers << @build if  @build

  super(numbers.join('.'))
end

Instance Attribute Details

#buildObject (readonly)

The build string



24
25
26
# File 'lib/ore/versions/version.rb', line 24

def build
  @build
end

#majorObject (readonly)

Major version number



15
16
17
# File 'lib/ore/versions/version.rb', line 15

def major
  @major
end

#minorObject (readonly)

Minor version number



18
19
20
# File 'lib/ore/versions/version.rb', line 18

def minor
  @minor
end

#patchObject (readonly)

Patch version number



21
22
23
# File 'lib/ore/versions/version.rb', line 21

def patch
  @patch
end

Class Method Details

.parse(string) ⇒ Version

Parses a version string.

Parameters:

  • string (String)

    The version string.

Returns:

  • (Version)

    The parsed version.



62
63
64
65
66
67
68
69
70
71
# File 'lib/ore/versions/version.rb', line 62

def self.parse(string)
  major, minor, patch, build = string.split('.',4)

  return self.new(
    (major || 0).to_i,
    (minor || 0).to_i,
    (patch || 0).to_i,
    build
  )
end