Class: SemanticRange::PreRelease
- Inherits:
-
Object
- Object
- SemanticRange::PreRelease
- Defined in:
- lib/semantic_range/pre_release.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #clear! ⇒ Object
- #convert(str) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(input) ⇒ PreRelease
constructor
A new instance of PreRelease.
- #length ⇒ Object
- #parse(str) ⇒ Object
- #to_s ⇒ Object
- #zero! ⇒ Object
Constructor Details
#initialize(input) ⇒ PreRelease
Returns a new instance of PreRelease.
5 6 7 |
# File 'lib/semantic_range/pre_release.rb', line 5 def initialize(input) @parts = parse(input) end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
3 4 5 |
# File 'lib/semantic_range/pre_release.rb', line 3 def parts @parts end |
Instance Method Details
#<=>(other) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/semantic_range/pre_release.rb', line 37 def <=>(other) return unless other.is_a?(self.class) return -1 if parts.any? && !other.parts.any? return 1 if !parts.any? && other.parts.any? return 0 if !parts.any? && !other.parts.any? i = 0 while true a = parts[i] b = other.parts[i] if a.nil? && b.nil? return 0 elsif b.nil? return 1 elsif a.nil? return -1 elsif a == b else return Version.compare_identifiers(a, b) end i += 1 end end |
#clear! ⇒ Object
29 30 31 |
# File 'lib/semantic_range/pre_release.rb', line 29 def clear! @parts = [] end |
#convert(str) ⇒ Object
13 14 15 |
# File 'lib/semantic_range/pre_release.rb', line 13 def convert(str) str.match(/^[0-9]+$/) ? str.to_i : str end |
#empty? ⇒ Boolean
21 22 23 |
# File 'lib/semantic_range/pre_release.rb', line 21 def empty? parts.empty? end |
#length ⇒ Object
17 18 19 |
# File 'lib/semantic_range/pre_release.rb', line 17 def length parts.length end |
#parse(str) ⇒ Object
9 10 11 |
# File 'lib/semantic_range/pre_release.rb', line 9 def parse(str) str.to_s.split('.').map { |id| convert(id) } end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/semantic_range/pre_release.rb', line 25 def to_s parts.join '.' end |
#zero! ⇒ Object
33 34 35 |
# File 'lib/semantic_range/pre_release.rb', line 33 def zero! @parts = [0] end |