Class: Tagit::Version
- Inherits:
-
Object
- Object
- Tagit::Version
- Includes:
- Comparable
- Defined in:
- lib/tagit/version.rb
Constant Summary collapse
- VERSION_REGEX =
/^v([0-9]+)\.([0-9]+)(?:\.([0-9]+))?$/
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(major, minor, patch = nil) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(major, minor, patch = nil) ⇒ Version
Returns a new instance of Version.
10 11 12 13 |
# File 'lib/tagit/version.rb', line 10 def initialize(major, minor, patch = nil) @major, @minor= major.to_i, minor.to_i @patch = patch.to_i if patch end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
6 7 8 |
# File 'lib/tagit/version.rb', line 6 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
6 7 8 |
# File 'lib/tagit/version.rb', line 6 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
6 7 8 |
# File 'lib/tagit/version.rb', line 6 def patch @patch end |
Class Method Details
.all ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/tagit/version.rb', line 24 def self.all lines = .split("\n") lines.inject([]) do |results, line| results << Version.new($1, $2, $3) if VERSION_REGEX.match(line) results end end |
.current ⇒ Object
20 21 22 |
# File 'lib/tagit/version.rb', line 20 def self.current all.sort.last end |
.from_s(str) ⇒ Object
15 16 17 18 |
# File 'lib/tagit/version.rb', line 15 def self.from_s(str) raise ArgumentError, "Not a conventional version string - '#{str}'" unless VERSION_REGEX.match(str) Version.new($1, $2, $3) end |
Instance Method Details
#<=>(other) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/tagit/version.rb', line 32 def <=> other return 1 if other.nil? [:major, :minor, :patch].each do |sym| compare = ((self.send(sym) || 0) <=> (other.send(sym) || 0)) return compare unless compare == 0 && sym != :patch end end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/tagit/version.rb', line 41 def to_s "v#{major}.#{minor}#{".#{patch}" if patch}" end |