Skip to content
Snippets Groups Projects
Commit 425cc76d authored by Markus Reiter's avatar Markus Reiter
Browse files

Refactor and document `PkgVersion`.

parent 72419630
No related branches found
No related tags found
No related merge requests found
...@@ -2,24 +2,22 @@ ...@@ -2,24 +2,22 @@
require "version" require "version"
# Combination of a version and a revision.
#
# @api private
class PkgVersion class PkgVersion
include Comparable include Comparable
extend Forwardable extend Forwardable
RX = /\A(.+?)(?:_(\d+))?\z/.freeze REGEX = /\A(.+?)(?:_(\d+))?\z/.freeze
private_constant :REGEX
attr_reader :version, :revision attr_reader :version, :revision
delegate [ # rubocop:disable Layout/HashAlignment delegate [:major, :minor, :patch, :major_minor, :major_minor_patch] => :version
:major,
:minor,
:patch,
:major_minor,
:major_minor_patch,
] => :version
def self.parse(path) def self.parse(path)
_, version, revision = *path.match(RX) _, version, revision = *path.match(REGEX)
version = Version.create(version) version = Version.create(version)
new(version, revision.to_i) new(version, revision.to_i)
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment