class Tins::StringVersion::Version
Public Class Methods
new(string)
click to toggle source
# File lib/tins/string_version.rb, line 11 def initialize(string) string =~ /\A\d+(\.\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 69 def <=>(other) pairs = array.zip(other.array) pairs.map! { |a, b| [ a.to_i, b.to_i ] } a, b = pairs.transpose a <=> b end
==(other)
click to toggle source
# File lib/tins/string_version.rb, line 76 def ==(other) (self <=> other).zero? end
[](level)
click to toggle source
# File lib/tins/string_version.rb, line 44 def [](level) array[level_of(level)] end
[]=(level, value)
click to toggle source
# File lib/tins/string_version.rb, line 48 def []=(level, value) level = level_of(level) value = value.to_i value >= 0 or raise ArgumentError, "version numbers can't contain negative numbers like #{value}" a = array a[level] = value a.map!(&:to_i) @version.replace a * ?. end
array()
click to toggle source
# File lib/tins/string_version.rb, line 80 def array @version.split(?.).map(&:to_i) end
Also aliased as: to_a
bump(level = array.size - 1)
click to toggle source
# File lib/tins/string_version.rb, line 27 def bump(level = array.size - 1) level = level_of(level) self[level] += 1 for l in level.succ..3 self[l] &&= 0 end self end
initialize_copy(source)
click to toggle source
Calls superclass method
# File lib/tins/string_version.rb, line 90 def initialize_copy(source) super @version = source.instance_variable_get(:@version).dup end
level_of(specifier)
click to toggle source
# File lib/tins/string_version.rb, line 36 def level_of(specifier) if specifier.respond_to?(:to_sym) LEVELS.fetch(specifier) else specifier end end
pred!()
click to toggle source
# File lib/tins/string_version.rb, line 64 def pred! self[-1] -= 1 self end
succ!()
click to toggle source
# File lib/tins/string_version.rb, line 59 def succ! self[-1] += 1 self end
to_s()
click to toggle source
# File lib/tins/string_version.rb, line 86 def to_s @version end
Also aliased as: inspect