Class: GemCheckUpdates::GemVersion
- Inherits:
-
Object
- Object
- GemCheckUpdates::GemVersion
- Includes:
- Comparable
- Defined in:
- lib/gem_check_updates/gem_version.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#number ⇒ Object
Returns the value of attribute number.
-
#patch ⇒ Object
Returns the value of attribute patch.
-
#pre ⇒ Object
Returns the value of attribute pre.
-
#pre_release ⇒ Object
Returns the value of attribute pre_release.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(number: '0', pre_release: false) ⇒ GemVersion
constructor
A new instance of GemVersion.
- #to_s ⇒ Object
- #version_specified? ⇒ Boolean
- #weighted_version ⇒ Object
Constructor Details
#initialize(number: '0', pre_release: false) ⇒ GemVersion
Returns a new instance of GemVersion.
14 15 16 17 18 |
# File 'lib/gem_check_updates/gem_version.rb', line 14 def initialize(number: '0', pre_release: false) @number = number @major, @minor, @patch, @pre = number.split('.').concat(%w[0 0 0 0]) @pre_release = pre_release end |
Instance Attribute Details
#major ⇒ Object
Returns the value of attribute major.
8 9 10 |
# File 'lib/gem_check_updates/gem_version.rb', line 8 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
9 10 11 |
# File 'lib/gem_check_updates/gem_version.rb', line 9 def minor @minor end |
#number ⇒ Object
Returns the value of attribute number.
7 8 9 |
# File 'lib/gem_check_updates/gem_version.rb', line 7 def number @number end |
#patch ⇒ Object
Returns the value of attribute patch.
10 11 12 |
# File 'lib/gem_check_updates/gem_version.rb', line 10 def patch @patch end |
#pre ⇒ Object
Returns the value of attribute pre.
11 12 13 |
# File 'lib/gem_check_updates/gem_version.rb', line 11 def pre @pre end |
#pre_release ⇒ Object
Returns the value of attribute pre_release.
12 13 14 |
# File 'lib/gem_check_updates/gem_version.rb', line 12 def pre_release @pre_release end |
Instance Method Details
#<=>(other) ⇒ Object
24 25 26 |
# File 'lib/gem_check_updates/gem_version.rb', line 24 def <=>(other) weighted_version <=> other.weighted_version end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/gem_check_updates/gem_version.rb', line 28 def to_s @number end |
#version_specified? ⇒ Boolean
20 21 22 |
# File 'lib/gem_check_updates/gem_version.rb', line 20 def version_specified? @number != '0' end |
#weighted_version ⇒ Object
32 33 34 35 36 37 |
# File 'lib/gem_check_updates/gem_version.rb', line 32 def weighted_version weights = [100, 10, 1] [@major, @minor, @patch].map(&:to_i) .map.with_index { |n, i| n * weights[i] } end |