Class: KXI::Application::Version
- Inherits:
-
Object
- Object
- KXI::Application::Version
- Defined in:
- lib/kxi/application/version.rb
Overview
Represents a version of semantic versioning 2.0.0 (semver.org)
Class Method Summary collapse
-
.parse(str) ⇒ KXI::Application::Version
Parses a version from its string representation.
Instance Method Summary collapse
-
#<(other) ⇒ bool
Checks whether this version is lower than other version.
-
#<=(other) ⇒ bool
Checks whether this version is lower than or equivalent to other version.
-
#==(other) ⇒ bool
Checks whether this version is equivalent to other version.
-
#>(other) ⇒ bool
Checks whether this version is grater than other version.
-
#>=(other) ⇒ bool
Checks whether this version is grater than or equivalent to other version.
-
#identifier ⇒ string
Gets the identifier of version.
-
#initialize(major, minor = 0, patch = 0, id = nil, meta = nil) ⇒ Version
constructor
Instantiates the Version class.
-
#major ⇒ integer
Gets the major number of version.
-
#metadata ⇒ string
Gets the metadata of version.
-
#minor ⇒ integer
Gets the number minor of version.
-
#patch ⇒ integer
Gets the number patch of version.
-
#to_s ⇒ string
Converts class to string representation.
Constructor Details
#initialize(major, minor = 0, patch = 0, id = nil, meta = nil) ⇒ Version
Instantiates the KXI::Application::Version class
43 44 45 46 47 48 49 |
# File 'lib/kxi/application/version.rb', line 43 def initialize(major, minor = 0, patch = 0, id = nil, = nil) @major = major @minor = minor @patch = patch @id = id @meta = end |
Class Method Details
.parse(str) ⇒ KXI::Application::Version
Parses a version from its string representation
100 101 102 103 104 |
# File 'lib/kxi/application/version.rb', line 100 def self.parse(str) m = /^\s*(?'ma'\d+)\s*(\.\s*(?'mi'\d+))?\s*(\.\s*(?'pt'\d+))?\s*(-\s*(?'id'[0-9A-Z\-.]+))?\s*(\+\s*(?'mt'[0-9A-Z\-.]+))?\s*$/mi.match(str) raise(KXI::Exceptions::ParseException.new('version', str)) if m == nil return Version.new(m['ma'].to_i, m['mi'] != nil ? m['mi'].to_i : 0, m['pt'] != nil ? m['pt'].to_i : 0, m['id'], m['mt']) end |
Instance Method Details
#<(other) ⇒ bool
Checks whether this version is lower than other version
66 67 68 69 70 71 72 |
# File 'lib/kxi/application/version.rb', line 66 def <(other) raise(KXI::Exceptions::InvalidTypeException.new(other.class, KXI::Application::Version)) unless other.is_a?(KXI::Application::Version) return true if @major < other.major or @minor < other.minor or @patch < other.patch return true if @id != nil and other.identifier == nil return true if @id != nil and other.identifier != nil and @id < other.identifier return false end |
#<=(other) ⇒ bool
Checks whether this version is lower than or equivalent to other version
76 77 78 79 80 81 82 83 |
# File 'lib/kxi/application/version.rb', line 76 def <=(other) raise(KXI::Exceptions::InvalidTypeException.new(other.class, KXI::Application::Version)) unless other.is_a?(KXI::Application::Version) return true if self == other return true if @major < other.major or @minor < other.minor or @patch < other.patch return true if @id != nil and other.identifier == nil return true if @id != nil and other.identifier != nil and @id < other.identifier return false end |
#==(other) ⇒ bool
Checks whether this version is equivalent to other version
59 60 61 62 |
# File 'lib/kxi/application/version.rb', line 59 def ==(other) return false unless other.is_a?(KXI::Application::Version) return (@major == other.major and @minor == other.minor and @patch == other.patch and @id == other.identifier) end |
#>(other) ⇒ bool
Checks whether this version is grater than other version
87 88 89 |
# File 'lib/kxi/application/version.rb', line 87 def >(other) return (not self <= other) end |
#>=(other) ⇒ bool
Checks whether this version is grater than or equivalent to other version
93 94 95 |
# File 'lib/kxi/application/version.rb', line 93 def >=(other) return (not self < other) end |
#identifier ⇒ string
Gets the identifier of version
27 28 29 |
# File 'lib/kxi/application/version.rb', line 27 def identifier @id end |
#major ⇒ integer
Gets the major number of version
9 10 11 |
# File 'lib/kxi/application/version.rb', line 9 def major @major end |
#metadata ⇒ string
Gets the metadata of version
33 34 35 |
# File 'lib/kxi/application/version.rb', line 33 def @meta end |
#minor ⇒ integer
Gets the number minor of version
15 16 17 |
# File 'lib/kxi/application/version.rb', line 15 def minor @minor end |
#patch ⇒ integer
Gets the number patch of version
21 22 23 |
# File 'lib/kxi/application/version.rb', line 21 def patch @patch end |
#to_s ⇒ string
Converts class to string representation
53 54 55 |
# File 'lib/kxi/application/version.rb', line 53 def to_s "#{@major}.#{@minor}.#{@patch}#{@id == nil ? '' : "-#{@id}"}#{@meta == nil ? '' : "+#{@meta}"}" end |