Class: Upfluence::Peer::Version::SemanticVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/upfluence/peer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major:, minor:, patch:, suffix: nil) ⇒ SemanticVersion

Returns a new instance of SemanticVersion.



9
10
11
12
13
14
# File 'lib/upfluence/peer.rb', line 9

def initialize(major:, minor:, patch:, suffix: nil)
  @major = major
  @minor = minor
  @patch = patch
  @suffix = suffix
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



7
8
9
# File 'lib/upfluence/peer.rb', line 7

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



7
8
9
# File 'lib/upfluence/peer.rb', line 7

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



7
8
9
# File 'lib/upfluence/peer.rb', line 7

def patch
  @patch
end

#suffixObject (readonly)

Returns the value of attribute suffix.



7
8
9
# File 'lib/upfluence/peer.rb', line 7

def suffix
  @suffix
end

Class Method Details

.parse(version) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/upfluence/peer.rb', line 24

def parse(version)
  return nil unless version

  v, suffix = version.split('-', 2)

  vs = v.split('.')

  return nil unless vs.count.eql? 3

  SemanticVersion.new(
    major:  vs[0].delete_prefix('v').to_i,
    minor:  vs[1].to_i,
    patch:  vs[2].to_i,
    suffix: suffix
  )
end

Instance Method Details

#to_sObject



16
17
18
19
20
21
# File 'lib/upfluence/peer.rb', line 16

def to_s
  v = "v#{@major}.#{@minor}.#{@patch}"

  v += "-#{@suffix}" if @suffix
  v
end