Class: Factorix::GameVersion

Inherits:
Data
  • Object
show all
Includes:
Comparable
Defined in:
lib/factorix/game_version.rb,
lib/factorix/game_version.rb

Overview

Represent a 4-component game version number (major.minor.patch-build)

This class represents Factorio’s game version format, which uses 64 bits (4 x 16-bit unsigned integers) to store version information.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#buildInteger (readonly)

Returns build version number (0-65535).

Returns:

  • (Integer)

    build version number (0-65535)



24
25
26
# File 'lib/factorix/game_version.rb', line 24

def build
  @build
end

#majorInteger (readonly)

Returns major version number (0-65535).

Returns:

  • (Integer)

    major version number (0-65535)



24
25
26
# File 'lib/factorix/game_version.rb', line 24

def major
  @major
end

#minorInteger (readonly)

Returns minor version number (0-65535).

Returns:

  • (Integer)

    minor version number (0-65535)



24
25
26
# File 'lib/factorix/game_version.rb', line 24

def minor
  @minor
end

#patchInteger (readonly)

Returns patch version number (0-65535).

Returns:

  • (Integer)

    patch version number (0-65535)



24
25
26
# File 'lib/factorix/game_version.rb', line 24

def patch
  @patch
end

Class Method Details

.from_numbers(major, minor, patch, build = 0) ⇒ GameVersion

Create GameVersion from four integers

Parameters:

  • major (Integer)

    major version number (0-65535)

  • minor (Integer)

    minor version number (0-65535)

  • patch (Integer)

    patch version number (0-65535)

  • build (Integer) (defaults to: 0)

    build version number (0-65535, defaults to 0)

Returns:

Raises:



67
68
69
70
71
72
73
74
# File 'lib/factorix/game_version.rb', line 67

def self.from_numbers(major, minor, patch, build=0)
  validate_component(major, :major)
  validate_component(minor, :minor)
  validate_component(patch, :patch)
  validate_component(build, :build)

  new(major:, minor:, patch:, build:)
end

.from_string(str) ⇒ GameVersion

Create GameVersion from version string “X.Y.Z-B” or “X.Y.Z”

Parameters:

  • str (String)

    version string in “X.Y.Z-B” format (build defaults to 0 if omitted)

Returns:

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/factorix/game_version.rb', line 41

def self.from_string(str)
  unless /\A(\d+)\.(\d+)\.(\d+)(?:-(\d+))?\z/ =~ str
    raise VersionParseError, "invalid version string: #{str.inspect}"
  end

  major = Integer($1)
  minor = Integer($2)
  patch = Integer($3)
  build = $4.nil? ? 0 : Integer($4)

  validate_component(major, :major)
  validate_component(minor, :minor)
  validate_component(patch, :patch)
  validate_component(build, :build)

  new(major:, minor:, patch:, build:)
end

Instance Method Details

#<=>(other) ⇒ Integer?

Compare with another GameVersion

Parameters:

Returns:

  • (Integer, nil)

    -1, 0, 1 for less than, equal to, greater than; nil if not comparable



92
93
94
95
96
# File 'lib/factorix/game_version.rb', line 92

def <=>(other)
  return nil unless other.is_a?(GameVersion)

  to_a <=> other.to_a
end

#to_aArray<Integer>

Convert to array of integers

Returns:

  • (Array<Integer>)

    Array containing [major, minor, patch, build]



86
# File 'lib/factorix/game_version.rb', line 86

def to_a = [major, minor, patch, build].freeze

#to_sString

Convert to string representation

Returns:

  • (String)

    Version string in format “X.Y.Z-B” or “X.Y.Z” if build is 0



81
# File 'lib/factorix/game_version.rb', line 81

def to_s = build.zero? ? "#{major}.#{minor}.#{patch}" : "#{major}.#{minor}.#{patch}-#{build}"