Sha256: bc48bce373cb5718c35fc49eb22dd69b7d772477519e487db09d399638d1171c

Contents?: true

Size: 569 Bytes

Versions: 6

Compression:

Stored size: 569 Bytes

Contents

class String
  def increment_version
    array = self.split('.')
    digits = 0
    index_of_last_digit = 0
    array.each_with_index {|x, i|
      if x.is_number? then
        digits += 1
        index_of_last_digit = i
      end
      break if (digits==3 || i==array.count-1) && x.is_number?
    }
    array[index_of_last_digit] = (array[index_of_last_digit].to_i + 1).to_s
    $stdout.puts 'Incrementing version...'
    array.join('.')
  end
  def increment_version!
    replace increment_version
  end
  def is_number?
    true if Float(self) rescue false
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
overview-0.0.10.pre.32 lib/helpers/string.rb
overview-0.0.9.pre.30 lib/helpers/string.rb
overview-0.0.8.pre.28 lib/helpers/string.rb
overview-0.0.7.pre.26 lib/helpers/string.rb
overview-0.0.6.pre.24 lib/helpers/string.rb
overview-0.0.5.pre.22 lib/helpers/string.rb