Class: P4ApiVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/P4/extconf.rb

Overview

This captures the version information of the P4API C++ library we're building against. This is mostly parsed into this structure and then spit out into a header file we compile into the Ruby API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor = nil) ⇒ P4ApiVersion

Returns a new instance of P4ApiVersion.



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'ext/P4/extconf.rb', line 298

def initialize(major, minor = nil)
  if (major.kind_of?(String) && !minor)
    if (major =~ /(\d+)\.(\d+)/)
      major = $1
      minor = $2
    else
      raise("Bad API version: #{major}")
    end
  end

  @major = major.to_i
  @minor = minor.to_i
  @type = nil

  @patchlevel = nil
  @suppdate = nil
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



323
324
325
# File 'ext/P4/extconf.rb', line 323

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



323
324
325
# File 'ext/P4/extconf.rb', line 323

def minor
  @minor
end

#patchlevelObject

Returns the value of attribute patchlevel.



322
323
324
# File 'ext/P4/extconf.rb', line 322

def patchlevel
  @patchlevel
end

#suppdateObject

Returns the value of attribute suppdate.



322
323
324
# File 'ext/P4/extconf.rb', line 322

def suppdate
  @suppdate
end

#typeObject (readonly)

Returns the value of attribute type.



323
324
325
# File 'ext/P4/extconf.rb', line 323

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object



339
340
341
342
343
344
# File 'ext/P4/extconf.rb', line 339

def <=>(other)
  hi = @major <=> other.major
  lo = @minor <=> other.minor

  return hi == 0 ? lo : hi
end

#set_type(type) ⇒ Object



316
317
318
319
320
# File 'ext/P4/extconf.rb', line 316

def set_type(type)
  if (type.kind_of?(String))
    @type = type
  end
end

#to_iObject



335
336
337
# File 'ext/P4/extconf.rb', line 335

def to_i
  major << 8 | minor
end

#to_sObject



327
328
329
330
331
332
333
# File 'ext/P4/extconf.rb', line 327

def to_s
  if (@type and not @type.empty?)
    "#{major}.#{minor}.#{@type.upcase}"
  else
    "#{major}.#{minor}"
  end
end