Class: Factorix::GameVersion
- Inherits:
-
Data
- Object
- Data
- Factorix::GameVersion
- 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
-
#build ⇒ Integer
readonly
Build version number (0-65535).
-
#major ⇒ Integer
readonly
Major version number (0-65535).
-
#minor ⇒ Integer
readonly
Minor version number (0-65535).
-
#patch ⇒ Integer
readonly
Patch version number (0-65535).
Class Method Summary collapse
-
.from_numbers(major, minor, patch, build = 0) ⇒ GameVersion
Create GameVersion from four integers.
-
.from_string(str) ⇒ GameVersion
Create GameVersion from version string “X.Y.Z-B” or “X.Y.Z”.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compare with another GameVersion.
-
#to_a ⇒ Array<Integer>
Convert to array of integers.
-
#to_s ⇒ String
Convert to string representation.
Instance Attribute Details
#build ⇒ Integer (readonly)
Returns build version number (0-65535).
24 25 26 |
# File 'lib/factorix/game_version.rb', line 24 def build @build end |
#major ⇒ Integer (readonly)
Returns major version number (0-65535).
24 25 26 |
# File 'lib/factorix/game_version.rb', line 24 def major @major end |
#minor ⇒ Integer (readonly)
Returns minor version number (0-65535).
24 25 26 |
# File 'lib/factorix/game_version.rb', line 24 def minor @minor end |
#patch ⇒ Integer (readonly)
Returns 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
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”
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
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_a ⇒ Array<Integer>
Convert to array of integers
86 |
# File 'lib/factorix/game_version.rb', line 86 def to_a = [major, minor, patch, build].freeze |
#to_s ⇒ String
Convert to string representation
81 |
# File 'lib/factorix/game_version.rb', line 81 def to_s = build.zero? ? "#{major}.#{minor}.#{patch}" : "#{major}.#{minor}.#{patch}-#{build}" |