Class: Versionaire::Version
- Inherits:
-
Object
- Object
- Versionaire::Version
- Includes:
- Comparable
- Defined in:
- lib/versionaire/version.rb
Overview
An immutable, semantic version value object.
Instance Attribute Summary collapse
-
#maintenance ⇒ Object
readonly
Returns the value of attribute maintenance.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(major: 0, minor: 0, maintenance: 0) ⇒ Version
constructor
A new instance of Version.
- #label ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(major: 0, minor: 0, maintenance: 0) ⇒ Version
Returns a new instance of Version.
22 23 24 25 26 27 |
# File 'lib/versionaire/version.rb', line 22 def initialize major: 0, minor: 0, maintenance: 0 @major = major @minor = minor @maintenance = maintenance validate end |
Instance Attribute Details
#maintenance ⇒ Object (readonly)
Returns the value of attribute maintenance.
8 9 10 |
# File 'lib/versionaire/version.rb', line 8 def maintenance @maintenance end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
8 9 10 |
# File 'lib/versionaire/version.rb', line 8 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
8 9 10 |
# File 'lib/versionaire/version.rb', line 8 def minor @minor end |
Class Method Details
.arguments(major, minor, maintenance) ⇒ Object
18 19 20 |
# File 'lib/versionaire/version.rb', line 18 def self.arguments major, minor, maintenance Hash[keys.zip [major, minor, maintenance]] end |
.format ⇒ Object
14 15 16 |
# File 'lib/versionaire/version.rb', line 14 def self.format /\Av?\d{1,}\.\d{1,}\.\d{1,}\z/ end |
.keys ⇒ Object
10 11 12 |
# File 'lib/versionaire/version.rb', line 10 def self.keys i(major minor maintenance) end |
Instance Method Details
#+(other) ⇒ Object
29 30 31 |
# File 'lib/versionaire/version.rb', line 29 def + other self.class.new self.class.arguments(*reduce(other, :+)) end |
#-(other) ⇒ Object
33 34 35 |
# File 'lib/versionaire/version.rb', line 33 def - other self.class.new self.class.arguments(*reduce(other, :-)) end |
#<=>(other) ⇒ Object
42 43 44 |
# File 'lib/versionaire/version.rb', line 42 def <=> other to_s <=> other.to_s end |
#==(other) ⇒ Object Also known as: eql?
37 38 39 |
# File 'lib/versionaire/version.rb', line 37 def == other other.is_a?(Version) && to_s == other.to_s end |
#hash ⇒ Object
46 47 48 |
# File 'lib/versionaire/version.rb', line 46 def hash [major, minor, maintenance, self.class].hash end |
#label ⇒ Object
50 51 52 |
# File 'lib/versionaire/version.rb', line 50 def label "v#{self}" end |
#to_a ⇒ Object
59 60 61 |
# File 'lib/versionaire/version.rb', line 59 def to_a [major, minor, maintenance] end |
#to_h ⇒ Object
63 64 65 |
# File 'lib/versionaire/version.rb', line 63 def to_h {major: major, minor: minor, maintenance: maintenance} end |
#to_s ⇒ Object Also known as: to_str
54 55 56 |
# File 'lib/versionaire/version.rb', line 54 def to_s "#{major}.#{minor}.#{maintenance}" end |