Class: RuboCop::SketchUp::SketchUpVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rubocop/sketchup/sketchup_version.rb

Defined Under Namespace

Classes: InvalidVersion

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_string) ⇒ SketchUpVersion #initialize(version, maintenance) ⇒ SketchUpVersion

Returns a new instance of SketchUpVersion.

Overloads:

  • #initialize(version_string) ⇒ SketchUpVersion

    Parameters:

    • version_string (String)
  • #initialize(version, maintenance) ⇒ SketchUpVersion

    Parameters:

    • version (Integer, Float)
    • maintenance (Integer)


19
20
21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#maintenanceObject (readonly)

Returns the value of attribute maintenance.



9
10
11
# File 'lib/rubocop/sketchup/sketchup_version.rb', line 9

def maintenance
  @maintenance
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/rubocop/sketchup/sketchup_version.rb', line 9

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rubocop/sketchup/sketchup_version.rb', line 41

def <=>(other)
  if version == other.version
    maintenance <=> other.maintenance
  else
    version <=> other.version
  end
end

#succSketchUpVersion?

Returns:



32
33
34
35
36
37
38
39
# 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_sString

Returns:

  • (String)


50
51
52
53
54
55
56
57
# 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