Class: SemverDialects::Maven::Version

Inherits:
BaseVersion show all
Defined in:
lib/semver_dialects/maven.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Attributes inherited from BaseVersion

#tokens

Instance Method Summary collapse

Methods inherited from BaseVersion

#<=>, #initialize, #is_zero?

Constructor Details

This class inherits a constructor from SemverDialects::BaseVersion

Instance Attribute Details

#additionObject

Returns the value of attribute addition.



15
16
17
# File 'lib/semver_dialects/maven.rb', line 15

def addition
  @addition
end

Instance Method Details

#to_aObject

Return an array similar to the one Maven generates when parsing versions.

$ java -jar ${MAVEN_HOME}/lib/maven-artifact-3.9.6.jar 1a1
Display parameters as parsed by Maven (in canonical form and as a list of tokens) and comparison result:
 1. 1a1 -> 1-alpha-1; tokens: [1, [alpha, [1]]]


23
24
25
26
27
# File 'lib/semver_dialects/maven.rb', line 23

def to_a
  return tokens if addition.nil?

  tokens.clone.append(addition.to_a)
end

#to_s(as_addition = false) ⇒ Object

rubocop:disable Style/OptionalBooleanParameter



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/semver_dialects/maven.rb', line 29

def to_s(as_addition = false) # rubocop:disable Style/OptionalBooleanParameter
  s = ''
  if tokens.any?
    s += '-' if as_addition
    s += tokens.map do |token|
      case token
      when String
        token
      when Integer
        case token
        when ALPHA
          'alpha'
        when BETA
          'beta'
        when MILESTONE
          'milestone'
        when RC
          'rc'
        when SNAPSHOT
          'snapshot'
        else
          token.to_s
        end
      end
    end.join('.')
  end
  s += addition.to_s(true) if addition
  s
end