VersionNumber

VersionNumber is a simplified form of a Tuple class desgined specifically for dealing with version numbers.

Methods
<=> =~ [] bump constraint_lambda inspect major method_missing minor new parse_constraint teeny to_s to_str
Included Modules
Public Class methods
constraint_lambda( constraint )

Parses a string constraint returning the operation as a lambda.

# File lib/more/facets/version.rb, line 113
  def self.constraint_lambda( constraint )
    op, val = *parse_constraint( constraint )
    lambda { |t| t.send(op, val) }
  end
new( *args )
# File lib/more/facets/version.rb, line 40
  def initialize( *args )
    args = args.join('.').split(/\W+/)
    @self = args.collect { |i| i.to_i }
  end
parse_constraint( constraint )
# File lib/more/facets/version.rb, line 118
  def self.parse_constraint( constraint )
    constraint = constraint.strip
    re = %r{^(=~|~>|<=|>=|==|=|<|>)?\s*(\d+(:?[-.]\d+)*)$}
    if md = re.match( constraint )
      if op = md[1]
        op = '=~' if op == '~>'
        op = '==' if op == '='
        val = new( *md[2].split(/\W+/) )
      else
        op = '=='
        val = new( *constraint.split(/\W+/) )
      end
    else
      raise ArgumentError, "invalid constraint"
    end
    return op, val
  end
Public Instance methods
<=>( other )

"Spaceship" comparsion operator.

# File lib/more/facets/version.rb, line 61
  def <=>( other )
    #other = other.to_t
    [@self.size, other.size].max.times do |i|
      c = @self[i] <=> other[i]
      return c if c != 0
    end
    0
  end
=~( other )

For pessimistic constraint (like ’~>’ in gems)

# File lib/more/facets/version.rb, line 72
  def =~( other )
    #other = other.to_t
    upver = other.dup
    upver[0] += 1
    @self >= other and @self < upver
  end
[](i)
# File lib/more/facets/version.rb, line 55
  def [](i)
    @self.fetch(i,0)
  end
bump(which=:teeny)
# File lib/more/facets/version.rb, line 92
  def bump(which=:teeny)
    case which
    when :major
      self.class.new(major+1)
    when :minor
      self.class.new(major, minor+1)
    when :teeny
      self.class.new(major, minor, teeny+1)
    else
      # ???
    end
  end
inspect()
# File lib/more/facets/version.rb, line 51
  def inspect
    @self.to_s
  end
major()

Major is the first number in the version series.

# File lib/more/facets/version.rb, line 81
  def major ; @self[0] ; end
method_missing( sym, *args, &blk )

Delegate to the array.

# File lib/more/facets/version.rb, line 107
  def method_missing( sym, *args, &blk )
    @self.send(sym, *args, &blk ) rescue super
  end
minor()

Minor is the second number in the version series.

# File lib/more/facets/version.rb, line 85
  def minor ; @self[1] || 0 ; end
teeny()

Teeny is third number in the version series.

# File lib/more/facets/version.rb, line 89
  def teeny ; @self[2] || 0 ; end
to_s()
# File lib/more/facets/version.rb, line 45
  def to_s ; @self.join('.') ; end
to_str()

This is here only becuase File.join calls it instead of to_s.

# File lib/more/facets/version.rb, line 49
  def to_str ; @self.join('.') ; end