Class: Invoker::Version
- Inherits:
-
Object
- Object
- Invoker::Version
- Includes:
- Comparable
- Defined in:
- lib/invoker/version.rb
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.
Instance Method Summary collapse
- #<=>(version) ⇒ Object
-
#initialize(number) ⇒ Version
constructor
A new instance of Version.
- #matches?(operator, number) ⇒ Boolean
- #next ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(number) ⇒ Version
Returns a new instance of Version.
6 7 8 9 10 11 |
# File 'lib/invoker/version.rb', line 6 def initialize(number) t_major, t_minor, t_patch = number.split('.') @major = t_major.to_i @minor = t_minor.to_i @patch = t_patch.to_i end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
4 5 6 |
# File 'lib/invoker/version.rb', line 4 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
4 5 6 |
# File 'lib/invoker/version.rb', line 4 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
4 5 6 |
# File 'lib/invoker/version.rb', line 4 def patch @patch end |
Instance Method Details
#<=>(version) ⇒ Object
17 18 19 20 21 |
# File 'lib/invoker/version.rb', line 17 def <=>(version) (major.to_i <=> version.major.to_i).nonzero? || (minor.to_i <=> version.minor.to_i).nonzero? || patch.to_i <=> version.patch.to_i end |
#matches?(operator, number) ⇒ Boolean
23 24 25 26 27 28 29 30 31 |
# File 'lib/invoker/version.rb', line 23 def matches?(operator, number) version = Version.new(number) self == version return self == version if operator == '=' return self > version if operator == '>' return self < version if operator == '<' return version <= self && version.next > self if operator == '~>' end |
#next ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/invoker/version.rb', line 33 def next next_splits = to_a if next_splits.length == 1 next_splits[0] += 1 else next_splits[-2] += 1 next_splits[-1] = 0 end Version.new(next_splits.join('.')) end |
#to_a ⇒ Object
13 14 15 |
# File 'lib/invoker/version.rb', line 13 def to_a [major, minor, patch].compact end |