Class: Factorix::MODVersion
- Inherits:
-
Data
- Object
- Data
- Factorix::MODVersion
- Includes:
- Comparable
- Defined in:
- lib/factorix/mod_version.rb,
lib/factorix/mod_version.rb
Overview
Represent a 3-component MOD version number (major.minor.patch)
This class represents Factorio’s MOD version format, which uses 24 bits (3 x 8-bit unsigned integers) to store version information.
Instance Attribute Summary collapse
-
#major ⇒ Integer
readonly
Major version number (0-255).
-
#minor ⇒ Integer
readonly
Minor version number (0-255).
-
#patch ⇒ Integer
readonly
Patch version number (0-255).
Class Method Summary collapse
-
.from_numbers(major, minor, patch) ⇒ MODVersion
Create MODVersion from three integers.
-
.from_string(str) ⇒ MODVersion
Create MODVersion from version string “X.Y.Z” or “X.Y”.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compare with another MODVersion.
-
#to_a ⇒ Array<Integer>
Convert to array of integers.
-
#to_s ⇒ String
Convert to string representation.
Instance Attribute Details
#major ⇒ Integer (readonly)
Returns major version number (0-255).
22 23 24 |
# File 'lib/factorix/mod_version.rb', line 22 def major @major end |
#minor ⇒ Integer (readonly)
Returns minor version number (0-255).
22 23 24 |
# File 'lib/factorix/mod_version.rb', line 22 def minor @minor end |
#patch ⇒ Integer (readonly)
Returns patch version number (0-255).
22 23 24 |
# File 'lib/factorix/mod_version.rb', line 22 def patch @patch end |
Class Method Details
.from_numbers(major, minor, patch) ⇒ MODVersion
Create MODVersion from three integers
69 70 71 72 73 74 75 |
# File 'lib/factorix/mod_version.rb', line 69 def self.from_numbers(major, minor, patch) validate_component(major, :major) validate_component(minor, :minor) validate_component(patch, :patch) new(major:, minor:, patch:) end |
.from_string(str) ⇒ MODVersion
Create MODVersion from version string “X.Y.Z” or “X.Y”
Accepts both 3-part (X.Y.Z) and 2-part (X.Y) version strings. For 2-part versions, patch defaults to 0.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/factorix/mod_version.rb', line 42 def self.from_string(str) if /\A(\d+)\.(\d+)\.(\d+)\z/ =~ str major = Integer($1, 10) minor = Integer($2, 10) patch = Integer($3, 10) elsif /\A(\d+)\.(\d+)\z/ =~ str major = Integer($1, 10) minor = Integer($2, 10) patch = 0 else raise VersionParseError, "invalid version string: #{str.inspect}" end validate_component(major, :major) validate_component(minor, :minor) validate_component(patch, :patch) new(major:, minor:, patch:) end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compare with another MODVersion
93 94 95 96 97 |
# File 'lib/factorix/mod_version.rb', line 93 def <=>(other) return nil unless other.is_a?(MODVersion) to_a <=> other.to_a end |
#to_a ⇒ Array<Integer>
Convert to array of integers
87 |
# File 'lib/factorix/mod_version.rb', line 87 def to_a = [major, minor, patch].freeze |
#to_s ⇒ String
Convert to string representation
82 |
# File 'lib/factorix/mod_version.rb', line 82 def to_s = "#{major}.#{minor}.#{patch}" |