class Version::Component

Attributes

digits[RW]
letter[RW]

Public Class Methods

new(component) click to toggle source

Creates a single Component of a version, consisting of digits and possibly a letter. For example, 1, 3a, 12, or 0.

# File lib/version/component.rb, line 11
def initialize(component)
  parts = component.split /(?=\D)/
  
  self.digits = parts[0].to_i
  self.letter = parts[1].to_s.strip
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/version/component.rb, line 46
def <=>(other)
  self.to_sortable_a <=> other.to_sortable_a
end
initialize_copy(other) click to toggle source
# File lib/version/component.rb, line 18
def initialize_copy(other)
  self.digits = other.digits
  self.letter = other.letter.dup
end
inspect() click to toggle source
# File lib/version/component.rb, line 66
def inspect
  self.to_s.inspect
end
next(pre = false) click to toggle source
# File lib/version/component.rb, line 31
def next(pre = false)
  self.dup.next!(pre)
end
next!(pre = false) click to toggle source
# File lib/version/component.rb, line 35
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?() click to toggle source
# File lib/version/component.rb, line 23
def prerelease?
  not self.letter.empty?
end
to_a() click to toggle source
# File lib/version/component.rb, line 54
def to_a
  [ self.digits, self.letter ]
end
to_i() click to toggle source
# File lib/version/component.rb, line 58
def to_i
  self.digits
end
to_s() click to toggle source
# File lib/version/component.rb, line 62
def to_s
  self.to_a.join
end
to_sortable_a() click to toggle source
# File lib/version/component.rb, line 50
def to_sortable_a
  [ self.digits, self.prerelease? ? 0 : 1, self.letter ]
end
unprerelease!() click to toggle source
# File lib/version/component.rb, line 27
def unprerelease!
  self.next! if self.prerelease?
end