# class GxG::Version

### Public Class Methods

new(params={}) click to toggle source

    # File lib/gxg/gxg_elements.rb, line 7
    def initialize(params={})
      unless params.is_a?(::Hash)
        params = {:interpret => (params.to_s)}
      end
      @encoded_value = encode(params)
    end

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/gxg/gxg_elements.rb, line 19
    def <=>(other)
      return @encoded_value <=> other.encoded_value()
    end

encoded_value() click to toggle source

    # File lib/gxg/gxg_elements.rb, line 16
    def encoded_value()
      @encoded_value
    end

increment(params={:revision => 1}) click to toggle source

    # File lib/gxg/gxg_elements.rb, line 28
    def increment(params={:revision => 1})
      current = decode({:value => @encoded_value})
      if current[:phase].is_a?(Hash)
        numeric_phase = current[:phase][:candidate].to_i + 2
      else
        case current[:phase]
        when :alpha
          numeric_phase = 0
        when :beta
          numeric_phase = 1
        when :release
          numeric_phase = 99
        end
      end
      if params[:phase].is_a?(Numeric)
        phase_increment = params[:phase]
      else
        phase_increment = 0
      end
      new_value = {}
      #
      if params[:revision].is_a?(Numeric)
        if (params[:revision].to_i + current[:revision]) > 99999
          params[:patch_level] = params[:patch_level].to_i + 1
          new_value[:revision] = 0
        else
          new_value[:revision] = (params[:revision].to_i + current[:revision])
        end
      else
        new_value[:revision] = current[:revision]
      end
      #
      if params[:patch_level].is_a?(Numeric)
        if (params[:patch_level].to_i + current[:patch_level]) > 9999
          phase_increment = phase_increment + 1
          new_value[:patch_level] = 0
        else
          new_value[:patch_level] = (params[:patch_level].to_i + current[:patch_level])
        end
      else
        new_value[:patch_level] = current[:patch_level]
      end
      #
      if phase_increment > 0
        if (phase_increment + numeric_phase) > 99
          params[:tiny] = params[:tiny].to_i + 1
          new_value[:phase] = 99
        else
          new_value[:phase] = (phase_increment + numeric_phase)
        end
      else
        new_value[:phase] = numeric_phase
      end
      #
      if params[:tiny].is_a?(Numeric)
        if (params[:tiny].to_i + current[:tiny]) > 999
          params[:minor] = params[:minor].to_i + 1
          new_value[:tiny] = 0
        else
          new_value[:tiny] = (params[:tiny].to_i + current[:tiny])
        end
      else
        new_value[:tiny] = current[:tiny]
      end
      #
      if params[:minor].is_a?(Numeric)
        if (params[:minor].to_i + current[:minor]) > 999
          params[:major] = params[:major].to_i + 1
          new_value[:minor] = 0
        else
          new_value[:minor] = (params[:minor].to_i + current[:minor])
        end
      else
        new_value[:minor] = current[:minor]
      end
      #
      if params[:major].is_a?(Numeric)
        new_value[:major] = current[:major] + params[:major].to_i
      else
        new_value[:major] = current[:major]
      end
      # convert phase numeric value to Symbol / Hash
      if (2..98).include?(new_value[:phase])
        new_value[:phase] = {:candidate => (new_value[:phase] - 2)}
      else
        case new_value[:phase]
        when 0
          new_value[:phase] = :alpha
        when 1
          new_value[:phase] = :beta
        when 99
          new_value[:phase] = :release
        end
      end
      #
      @encoded_value = encode(new_value)
      self
    end

inspect() click to toggle source

    # File lib/gxg/gxg_elements.rb, line 25
    def inspect()
      value.inspect
    end

to_s() click to toggle source

    # File lib/gxg/gxg_elements.rb, line 22
    def to_s()
      value.inspect
    end

value() click to toggle source

    # File lib/gxg/gxg_elements.rb, line 13
    def value()
      decode({:value => @encoded_value})
    end