Sha256: 58042c4fa18ccd3d3eeb723fab0bef7afe4cb455e2d6d866fa951f2ad314d5b5

Contents?: true

Size: 972 Bytes

Versions: 4

Compression:

Stored size: 972 Bytes

Contents

module BuildMaster
class VersionNumberFile
  attr_reader :build_number
  
  def initialize(file)
    @file = file
    self.version= @file.load.strip
  end
  
  def increase_build
    @build_number = @build_number + 1
    @file.save("#{version_number}")
  end
  
  def version_number
    "#{@version_number}.#{@build_number}"
  end
  
  def version= (value)
    index = dot_position_for_buildnumber(value)
    @version_number = value
    @build_number = 0
    unless index.nil?
      @version_number = value[0..index - 1]
      @build_number = value[index + 1..value.length - 1].to_i
    end
  end
  
  def dot_position_for_buildnumber(value)
    splitted = value.split('.')
    result = nil
    if splitted.size > 2 && splitted[splitted.size - 1].length > 0
      result = value.length - splitted[splitted.size - 1].length - 1
    end
    return result
  end
  
  private :dot_position_for_buildnumber
  
  def to_s
    "#{version_number}.#{build_number}"
  end
  
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
BuildMaster-1.0.6 lib/buildmaster/project/version_number_file.rb
BuildMaster-1.0.9 lib/buildmaster/project/version_number_file.rb
BuildMaster-1.1.12 lib/buildmaster/project/version_number_file.rb
BuildMaster-1.1.9 lib/buildmaster/project/version_number_file.rb