Parent

Included Modules

Files

Tins::StringVersion::Version

Public Class Methods

new(string) click to toggle source
# File lib/tins/string_version.rb, line 8
def initialize(string)
  string =~ /\A[\.\d]+\z/ or raise ArgumentError, "#{string.inspect} isn't a version number"
  @version = string.frozen? ? string.dup : string
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/tins/string_version.rb, line 67
def <=>(other)
  pairs = array.zip(other.array)
  pairs.map! { |a, b| [ a.nil? ? 0 : a, b.nil? ? 0 : b ] }
  a, b = pairs.transpose
  a <=> b
end
==(other) click to toggle source
# File lib/tins/string_version.rb, line 74
def ==(other)
  (self <=> other).zero?
end
[](index) click to toggle source
# File lib/tins/string_version.rb, line 45
def [](index)
  array[index]
end
[]=(index, value) click to toggle source
# File lib/tins/string_version.rb, line 49
def []=(index, value)
  value = value.to_i
  value >= 0 or raise ArgumentError, "version numbers can't contain negative numbers like #{value}"
  a = array
  @array = nil
  a[index] = value
  a.map! { |x| x.nil? ? 0 : x }
  @version.replace a * '.'
end
array() click to toggle source
# File lib/tins/string_version.rb, line 78
def array
   @version.split('.').map(&:to_i)
end
Also aliased as: to_a
build() click to toggle source
# File lib/tins/string_version.rb, line 29
def build
  self[2]
end
build=(number) click to toggle source
# File lib/tins/string_version.rb, line 33
def build=(number)
  self[2] = number
end
inspect() click to toggle source
Alias for: to_s
major() click to toggle source
# File lib/tins/string_version.rb, line 13
def major
  self[0]
end
major=(number) click to toggle source
# File lib/tins/string_version.rb, line 17
def major=(number)
  self[0] = number
end
minor() click to toggle source
# File lib/tins/string_version.rb, line 21
def minor
  self[1]
end
minor=(number) click to toggle source
# File lib/tins/string_version.rb, line 25
def minor=(number)
  self[1] = number
end
pred!() click to toggle source
# File lib/tins/string_version.rb, line 63
def pred!
  self[-1] -= 1
end
revision() click to toggle source
# File lib/tins/string_version.rb, line 37
def revision
  self[3]
end
revision=(number) click to toggle source
# File lib/tins/string_version.rb, line 41
def revision=(number)
  self[3] = number
end
succ!() click to toggle source
# File lib/tins/string_version.rb, line 59
def succ!
  self[-1] += 1
end
to_a() click to toggle source
Alias for: array
to_s() click to toggle source
# File lib/tins/string_version.rb, line 84
def to_s
  @version
end
Also aliased as: inspect
version() click to toggle source
# File lib/tins/string_version.rb, line 90
def version
  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.