Class: Version::Component
- Inherits:
-
Object
- Object
- Version::Component
- Defined in:
- lib/asrake/version/component.rb
Overview
(The MIT License)
Copyright © 2010-2010 Stephen Touset
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Instance Attribute Summary collapse
-
#digits ⇒ Object
Returns the value of attribute digits.
-
#letter ⇒ Object
Returns the value of attribute letter.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(component) ⇒ Component
constructor
Creates a single Component of a version, consisting of digits and possibly a letter.
- #initialize_copy(other) ⇒ Object
- #inspect ⇒ Object
- #next(pre = false) ⇒ Object
- #next!(pre = false) ⇒ Object
- #prerelease? ⇒ Boolean
- #to_a ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_sortable_a ⇒ Object
- #unprerelease! ⇒ Object
Constructor Details
#initialize(component) ⇒ Component
Creates a single Component of a version, consisting of digits and possibly a letter. For example, 1
, 3a
, 12
, or 0
.
32 33 34 35 36 37 |
# File 'lib/asrake/version/component.rb', line 32 def initialize(component) parts = component.split /(?=\D)/ self.digits = parts[0].to_i self.letter = parts[1].to_s.strip end |
Instance Attribute Details
#digits ⇒ Object
Returns the value of attribute digits.
25 26 27 |
# File 'lib/asrake/version/component.rb', line 25 def digits @digits end |
#letter ⇒ Object
Returns the value of attribute letter.
26 27 28 |
# File 'lib/asrake/version/component.rb', line 26 def letter @letter end |
Instance Method Details
#<=>(other) ⇒ Object
67 68 69 |
# File 'lib/asrake/version/component.rb', line 67 def <=>(other) self.to_sortable_a <=> other.to_sortable_a end |
#initialize_copy(other) ⇒ Object
39 40 41 42 |
# File 'lib/asrake/version/component.rb', line 39 def initialize_copy(other) self.digits = other.digits self.letter = other.letter.dup end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/asrake/version/component.rb', line 87 def inspect self.to_s.inspect end |
#next(pre = false) ⇒ Object
52 53 54 |
# File 'lib/asrake/version/component.rb', line 52 def next(pre = false) self.dup.next!(pre) end |
#next!(pre = false) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/asrake/version/component.rb', line 56 def next!(pre = false) case when ( pre and self.prerelease?) then self.letter.next! when ( pre and not self.prerelease?) then self.letter = 'a' when (not pre and self.prerelease?) then self.letter = '' when (not pre and not self.prerelease?) then self.digits = self.digits.next end self end |
#prerelease? ⇒ Boolean
44 45 46 |
# File 'lib/asrake/version/component.rb', line 44 def prerelease? not self.letter.empty? end |
#to_a ⇒ Object
75 76 77 |
# File 'lib/asrake/version/component.rb', line 75 def to_a [ self.digits, self.letter ] end |
#to_i ⇒ Object
79 80 81 |
# File 'lib/asrake/version/component.rb', line 79 def to_i self.digits end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/asrake/version/component.rb', line 83 def to_s self.to_a.join end |
#to_sortable_a ⇒ Object
71 72 73 |
# File 'lib/asrake/version/component.rb', line 71 def to_sortable_a [ self.digits, self.prerelease? ? 0 : 1, self.letter ] end |
#unprerelease! ⇒ Object
48 49 50 |
# File 'lib/asrake/version/component.rb', line 48 def unprerelease! self.next! if self.prerelease? end |