Parent

Included Modules

VersionNumber

VersionNumber

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

Public Class Methods

constraint_lambda( constraint ) click to toggle source

Parses a string constraint returning the operation as a lambda.

     # File lib/more/facets/version.rb, line 113
113:   def self.constraint_lambda( constraint )
114:     op, val = *parse_constraint( constraint )
115:     lambda { |t| t.send(op, val) }
116:   end
new( *args ) click to toggle source
    # File lib/more/facets/version.rb, line 40
40:   def initialize( *args )
41:     args = args.join('.').split(/\W+/)
42:     @self = args.collect { |i| i.to_i }
43:   end
parse_constraint( constraint ) click to toggle source
     # File lib/more/facets/version.rb, line 118
118:   def self.parse_constraint( constraint )
119:     constraint = constraint.strip
120:     re = %{^(=~|~>|<=|>=|==|=|<|>)?\s*(\d+(:?[-.]\d+)*)$}
121:     if md = re.match( constraint )
122:       if op = md[1]
123:         op = '=~' if op == '~>'
124:         op = '==' if op == '='
125:         val = new( *md[2].split(/\W+/) )
126:       else
127:         op = '=='
128:         val = new( *constraint.split(/\W+/) )
129:       end
130:     else
131:       raise ArgumentError, "invalid constraint"
132:     end
133:     return op, val
134:   end

Public Instance Methods

<=>( other ) click to toggle source

“Spaceship” comparsion operator.

    # File lib/more/facets/version.rb, line 61
61:   def <=>( other )
62:     #other = other.to_t
63:     [@self.size, other.size].max.times do |i|
64:       c = @self[i] <=> other[i]
65:       return c if c != 0
66:     end
67:     0
68:   end
=~( other ) click to toggle source

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

    # File lib/more/facets/version.rb, line 72
72:   def =~( other )
73:     #other = other.to_t
74:     upver = other.dup
75:     upver[0] += 1
76:     @self >= other and @self < upver
77:   end
[](i) click to toggle source
    # File lib/more/facets/version.rb, line 55
55:   def [](i)
56:     @self.fetch(i,0)
57:   end
bump(which=:teeny) click to toggle source
     # File lib/more/facets/version.rb, line 92
 92:   def bump(which=:teeny)
 93:     case which
 94:     when :major
 95:       self.class.new(major+1)
 96:     when :minor
 97:       self.class.new(major, minor+1)
 98:     when :teeny
 99:       self.class.new(major, minor, teeny+1)
100:     else
101:       # ???
102:     end
103:   end
inspect() click to toggle source
    # File lib/more/facets/version.rb, line 51
51:   def inspect
52:     @self.to_s
53:   end
major() click to toggle source

Major is the first number in the version series.

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

Delegate to the array.

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

Minor is the second number in the version series.

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

Teeny is third number in the version series.

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

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

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.