Class: GitSu::Version
- Inherits:
-
Object
- Object
- GitSu::Version
- Defined in:
- lib/gitsu/version.rb
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- REGEX =
/(\d+)\.(\d+).(\d+)/
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
- #eql?(other) ⇒ Boolean
-
#initialize(major, minor, patch) ⇒ Version
constructor
A new instance of Version.
- #next_minor ⇒ Object
- #next_patch ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(major, minor, patch) ⇒ Version
Returns a new instance of Version.
46 47 48 |
# File 'lib/gitsu/version.rb', line 46 def initialize(major, minor, patch) @major, @minor, @patch = major, minor, patch end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
45 46 47 |
# File 'lib/gitsu/version.rb', line 45 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
45 46 47 |
# File 'lib/gitsu/version.rb', line 45 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
45 46 47 |
# File 'lib/gitsu/version.rb', line 45 def patch @patch end |
Class Method Details
.current ⇒ Object
31 32 33 |
# File 'lib/gitsu/version.rb', line 31 def self.current Version.parse(VERSION) end |
.parse(string) ⇒ Object
25 26 27 28 29 |
# File 'lib/gitsu/version.rb', line 25 def self.parse(string) raise ParseError, "Couldn't parse string '#{string}' as version" unless REGEX =~ string parts = REGEX.match(string)[1..3].map {|e| e.to_i } Version.new(*parts) end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 |
# File 'lib/gitsu/version.rb', line 58 def ==(other) eql? other end |
#eql?(other) ⇒ Boolean
62 63 64 |
# File 'lib/gitsu/version.rb', line 62 def eql?(other) major = other.major && minor == other.minor && patch == other.patch end |
#next_minor ⇒ Object
50 51 52 |
# File 'lib/gitsu/version.rb', line 50 def next_minor Version.new(@major, @minor + 1, 0) end |
#next_patch ⇒ Object
54 55 56 |
# File 'lib/gitsu/version.rb', line 54 def next_patch Version.new(@major, @minor, @patch + 1) end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/gitsu/version.rb', line 66 def to_s "#{major}.#{minor}.#{patch}" end |