Class: Nauvisian::Version24

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Version24

Returns a new instance of Version24.



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

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

Instance Method Details

#<=>(other) ⇒ Object



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

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

#to_aObject



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

def to_a = @version.dup.freeze

#to_sObject



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

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