class VersionRecord::Prerelease

Public Class Methods

build(string) click to toggle source
# File lib/version_record/prerelease.rb, line 5
def self.build(string)
  new(".#{string}") if string.present?
end
new(string) click to toggle source
# File lib/version_record/prerelease.rb, line 9
def initialize(string)
  @string = string
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/version_record/prerelease.rb, line 29
def <=>(other)
  return unless other.is_a?(Prerelease)

  if first_segment == other.first_segment
    compare_by_tail(other)
  else
    compare_by_first_segment(other)
  end
end
first_segment() click to toggle source
# File lib/version_record/prerelease.rb, line 25
def first_segment
  @first_segment ||= at(0)
end
name() click to toggle source
# File lib/version_record/prerelease.rb, line 17
def name
  @string[1..-1]
end
tail() click to toggle source
# File lib/version_record/prerelease.rb, line 21
def tail
  @tail ||= self.class.build(at(1..-1).join('.'))
end
to_s() click to toggle source
# File lib/version_record/prerelease.rb, line 13
def to_s
  @string
end

Private Instance Methods

at(index) click to toggle source
# File lib/version_record/prerelease.rb, line 41
def at(index)
  to_a[index]
end
compare_by_first_segment(other) click to toggle source
# File lib/version_record/prerelease.rb, line 55
def compare_by_first_segment(other)
  if int?(first_segment) && int?(other.first_segment)
    first_segment.to_i <=> other.first_segment.to_i
  else
    first_segment <=> other.first_segment
  end
end
compare_by_tail(other) click to toggle source
# File lib/version_record/prerelease.rb, line 49
def compare_by_tail(other)
  return  1 if self.tail && other.tail.nil?
  return -1 if self.tail.nil? && other.tail
  self.tail <=> other.tail
end
int?(str) click to toggle source
# File lib/version_record/prerelease.rb, line 63
def int?(str)
  !!Integer(str)
rescue ArgumentError, TypeError
  false
end
to_a() click to toggle source
# File lib/version_record/prerelease.rb, line 45
def to_a
  name.split('.')
end