class RuboCop::SketchUp::SketchUpVersion

Constants

VALID_VERSIONS

This list is compiled from the list of versions reported by YARD when running the `versions` template on the API stubs repository;

yardoc -t versions -f text

The second item in the array is maintenance annotation

VERSION_NUMBER_REGEX

Attributes

maintenance[R]
version[R]

Public Class Methods

new(*args) click to toggle source

@overload initialize(version_string)

@param [String] version_string

@overload initialize(version, maintenance)

@param [Integer, Float] version
@param [Integer] maintenance
# File lib/rubocop/sketchup/sketchup_version.rb, line 19
def initialize(*args)
  case args.size
  when 1
    @version, @maintenance = parse_version(args.first)
  when 2
    validate(args)
    @version, @maintenance = args
  else
    raise ArgumentError, "expected 1..2 arguments, got #{args.size}"
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/rubocop/sketchup/sketchup_version.rb, line 41
def <=>(other)
  if version == other.version
    maintenance <=> other.maintenance
  else
    version <=> other.version
  end
end
succ() click to toggle source

@return [SketchUpVersion, nil]

# File lib/rubocop/sketchup/sketchup_version.rb, line 32
def succ
  version_parts = [@version, @maintenance]
  index = VALID_VERSIONS.index(version_parts)
  next_version_parts = VALID_VERSIONS[index + 1]
  return nil if next_version_parts.nil?

  self.class.new(*next_version_parts)
end
to_s() click to toggle source

@return [String]

# File lib/rubocop/sketchup/sketchup_version.rb, line 50
def to_s
  string_version = version < 2013 ? version.to_f : version.to_i
  if maintenance > 0
    "SketchUp #{string_version} M#{maintenance}"
  else
    "SketchUp #{string_version}"
  end
end

Private Instance Methods

parse_version(version) click to toggle source

@param [String] version @return [Array(Float, Integer)]

# File lib/rubocop/sketchup/sketchup_version.rb, line 96
def parse_version(version)
  v = 0
  m = 0
  case version
  when String
    # Treat all LayOut versions as SketchUp versions for now.
    normalized_version = version.gsub('LayOut', 'SketchUp')
    result = normalized_version.match(VERSION_NUMBER_REGEX)
    if result
      v = result.captures[0].to_f
      m = (result.captures[1] || '0').to_i
    end
  when Numeric
    v = version
    m = 0
  end
  validate([v, m])
end
validate(version_parts) click to toggle source

@param [Array(Float, Integer)] version_parts

# File lib/rubocop/sketchup/sketchup_version.rb, line 116
def validate(version_parts)
  unless VALID_VERSIONS.include?(version_parts)
    version = version_parts.join('.')
    raise InvalidVersion, "#{version} is not a valid SketchUp version"
  end

  version_parts
end