Class: Liferaft::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/liferaft/version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_string) ⇒ Version

Returns a new instance of Version.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/liferaft/version.rb', line 9

def initialize(version_string)
  components = version_string.downcase.split(/[a-z]/)
  character = version_string.downcase.gsub(/[^a-z]/, '')

  if character.length > 2 || character.length == 0
    @major = @minor = @patch = @build = 0
    return
  end

  @major = components[0].to_i
  @minor = character.ord - 'a'.ord
  @patch = components[1].to_i / 1000
  @build = (character.length == 2 ? character[-1].ord : 0) + components[1].to_i % 1000
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



7
8
9
# File 'lib/liferaft/version.rb', line 7

def build
  @build
end

#majorObject (readonly)

Returns the value of attribute major.



7
8
9
# File 'lib/liferaft/version.rb', line 7

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



7
8
9
# File 'lib/liferaft/version.rb', line 7

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



7
8
9
# File 'lib/liferaft/version.rb', line 7

def patch
  @patch
end

Instance Method Details

#<(other) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/liferaft/version.rb', line 36

def <(other)
  return true if major < other.major
  return false if major != other.major
  return true if minor < other.minor
  return false if minor != other.minor
  return true if patch < other.patch
  return false if patch != other.patch
  build < other.build
end

#<=(other) ⇒ Object



46
47
48
# File 'lib/liferaft/version.rb', line 46

def <=(other)
  self < other || other == self
end

#==(other) ⇒ Object



50
51
52
53
54
# File 'lib/liferaft/version.rb', line 50

def ==(other)
  other.instance_of?(self.class) &&
    major == other.major && minor == other.minor &&
    patch == other.patch && build == other.build
end

#>(other) ⇒ Object



28
29
30
# File 'lib/liferaft/version.rb', line 28

def >(other)
  other < self
end

#>=(other) ⇒ Object



32
33
34
# File 'lib/liferaft/version.rb', line 32

def >=(other)
  other < self || other == self
end

#to_sObject



24
25
26
# File 'lib/liferaft/version.rb', line 24

def to_s
  return "#{@major}.#{@minor}.#{@patch} Build #{@build}"
end