class Liferaft::Version

Attributes

build[R]
major[R]
minor[R]
patch[R]

Public Class Methods

new(version_string) click to toggle source
# File lib/liferaft/version.rb, line 11
def initialize(version_string)
  components = version_string.downcase.split(/[a-z]/)
  character = version_string.downcase.gsub(/[^a-z]/, '')

  if character.length > 2 || character.empty?
    @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

Public Instance Methods

<=>(other) click to toggle source
# File lib/liferaft/version.rb, line 30
def <=>(other)
  %i(major minor patch build).lazy.map do |component|
    send(component) <=> other.send(component)
  end.find(&:nonzero?) || 0
end
to_s() click to toggle source
# File lib/liferaft/version.rb, line 26
def to_s
  "#{@major}.#{@minor}.#{@patch} Build #{@build}"
end