Class: Versionary::VersionNumber
- Inherits:
-
Object
- Object
- Versionary::VersionNumber
- Includes:
- Comparable
- Defined in:
- lib/versionary/version_number.rb
Constant Summary collapse
- VERSION_PATTERN =
/^\d+\.\d+\.\d+$/
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#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_version) ⇒ Object
-
#initialize(version) ⇒ VersionNumber
constructor
A new instance of VersionNumber.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ VersionNumber
Returns a new instance of VersionNumber.
14 15 16 17 18 19 20 |
# File 'lib/versionary/version_number.rb', line 14 def initialize version raise NotAVersionComplaint.about version if not a_recognised? version number = infer_from version @major = value_of :major, number @minor = value_of :minor, number @build = value_of :build, number end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
6 7 8 |
# File 'lib/versionary/version_number.rb', line 6 def build @build end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
6 7 8 |
# File 'lib/versionary/version_number.rb', line 6 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
6 7 8 |
# File 'lib/versionary/version_number.rb', line 6 def minor @minor end |
Class Method Details
.of(version) ⇒ Object
10 11 12 |
# File 'lib/versionary/version_number.rb', line 10 def self.of version self.new version end |
Instance Method Details
#<=>(other_version) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/versionary/version_number.rb', line 22 def <=> other_version with_other_version = VersionNumber.of(other_version) if other_version.class == String with_other_version = other_version if other_version.class == self.class compare(self, with_other_version) end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/versionary/version_number.rb', line 29 def to_s "#{@major}.#{@minor}.#{@build}" end |