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 != 1
    @major = @minor = @patch = @build = 0
    return
  end

  @major = components[0].to_i
  @minor = character.ord - 'a'.ord
  @patch = components[1].to_i / 1000
  @build = 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



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

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

#<=(other) ⇒ Object



39
40
41
# File 'lib/liferaft/version.rb', line 39

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

#==(other) ⇒ Object



43
44
45
46
47
# File 'lib/liferaft/version.rb', line 43

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

#>(other) ⇒ Object



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

def >(other)
  other < self
end

#>=(other) ⇒ Object



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

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