Class: Nauvisian::Version64

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nauvisian/version64.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Version64

Returns a new instance of Version64.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nauvisian/version64.rb', line 10

def initialize(*args)
  case args
  in [String] if /\A(\d+)\.(\d+)\.(\d+)(?:-(\d+))?\z/ =~ args[0]
    @version = [Integer($1), Integer($2), Integer($3), $4.nil? ? 0 : Integer($4)]
  in [Integer, Integer, Integer, Integer] if args.all? {|e| e.is_a?(Numeric) && e.integer? && e.between?(0, UINT16_MAX) }
    @version = args
  else
    raise ArgumentError, "Expect version string or 4-tuple: %p" % [args]
  end
  @version.freeze
  freeze
end

Instance Method Details

#<=>(other) ⇒ Object



31
# File 'lib/nauvisian/version64.rb', line 31

def <=>(other) = @version <=> other.version

#to_aObject



30
# File 'lib/nauvisian/version64.rb', line 30

def to_a = @version.dup.freeze

#to_sObject



29
# File 'lib/nauvisian/version64.rb', line 29

def to_s = "%d.%d.%d-%d" % @version