Class: EpiDocValidator::SemVer

Inherits:
Object
  • Object
show all
Defined in:
lib/epi_doc_validator/sem_ver.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(semver) ⇒ SemVer

Returns a new instance of SemVer.



7
8
9
10
11
12
13
14
15
# File 'lib/epi_doc_validator/sem_ver.rb', line 7

def initialize(semver)
  @semver = semver

  numbers, @patch = *semver.split('-')

  if semver.match?(/\A\d/)
    @components = numbers.split('.').map(&:to_i)
  end
end

Instance Attribute Details

#semverObject (readonly)

Returns the value of attribute semver.



25
26
27
# File 'lib/epi_doc_validator/sem_ver.rb', line 25

def semver
  @semver
end

Class Method Details

.sort(versions) ⇒ Object



3
4
5
# File 'lib/epi_doc_validator/sem_ver.rb', line 3

def self.sort(versions)
  versions.map { |v| new(v) }.sort.map(&:semver)
end

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/epi_doc_validator/sem_ver.rb', line 17

def <=>(other)
  return 0 if semver == other.semver

  return compare_strings(other) if string? || other.string?

  compare_components(other)
end