Class: RuboCop::SketchUp::SketchUpVersion
- Includes:
- Comparable
- Defined in:
- lib/rubocop/sketchup/sketchup_version.rb
Defined Under Namespace
Classes: InvalidVersion
Instance Attribute Summary collapse
-
#maintenance ⇒ Object
readonly
Returns the value of attribute maintenance.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(*args) ⇒ SketchUpVersion
constructor
A new instance of SketchUpVersion.
- #succ ⇒ SketchUpVersion?
- #to_s ⇒ String
Constructor Details
#initialize(version_string) ⇒ SketchUpVersion #initialize(version, maintenance) ⇒ SketchUpVersion
Returns a new instance of SketchUpVersion.
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
#maintenance ⇒ Object (readonly)
Returns the value of attribute maintenance.
9 10 11 |
# File 'lib/rubocop/sketchup/sketchup_version.rb', line 9 def maintenance @maintenance end |
#version ⇒ Object (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 |
#succ ⇒ SketchUpVersion?
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_s ⇒ 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 |