class Gemspec::Version

Constants

IllegalFormat

Attributes

data[RW]

Public Class Methods

new(string_or_array) click to toggle source
# File lib/gemspec/bump.rb, line 9
def initialize(string_or_array)
  @data = string_or_array
  @data = @data.split('.') if string_or_array.is_a? String
  raise IllegalFormat, to_s unless @data.all? {|item| item.is_a? Integer or item =~ /^\d*$/ }
  @data.map!(&:to_i)
end

Public Instance Methods

==(other) click to toggle source
# File lib/gemspec/bump.rb, line 16
def ==(other)
  data == other.data
end
apply(diff) click to toggle source
# File lib/gemspec/bump.rb, line 24
def apply(diff)
  my_data_r = data.reverse
  diff_data_r = diff.data.reverse
  result = my_data_r.zip(diff_data_r).map do |first, second|
    first = if second =~ /^[+-]/
        first + second.to_i
      else
        (second and second.to_i) or first
      end
    first
  end.reverse
  Version.new(result)
end
to_s() click to toggle source
# File lib/gemspec/bump.rb, line 20
def to_s
  @data.join(".")
end