Class: OCI8::OracleVersion

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/oci8/oracle_version.rb

Overview

A data class, representing Oracle version.

Oracle version is represented by five numbers: major, minor, update, patch and port_update.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil) ⇒ OracleVersion

Creates a OCI8::OracleVersion object.

If the first argument arg is a String, it is parsed as dotted version string. If it is bigger than 0x08000000, it is parsed as a number contains 5-digit Oracle version. Otherwise, it is used as a major version and the rest arguments are minor, update, patch and port_update. Unspecified version numbers are zeros by default.

Example

oraver = OCI8::OracleVersion.new('10.2.0.4')
oraver.major       # => 10
oraver.minor       # =>  2
oraver.update      # =>  0
oraver.patch       # =>  4
oraver.port_update # =>  0

oraver = OCI8::OracleVersion.new(0x0a200400)
oraver.major       # => 10
oraver.minor       # =>  2
oraver.update      # =>  0
oraver.patch       # =>  4
oraver.port_update # =>  0


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/oci8/oracle_version.rb', line 50

def initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil)
  if arg.is_a? String
    major, minor, update, patch, port_update = arg.split('.').collect do |v|
      v.to_i
    end
  elsif arg >= 0x08000000
    major  = (arg & 0xFF000000) >> 24
    minor  = (arg & 0x00F00000) >> 20
    update = (arg & 0x000FF000) >> 12
    patch  = (arg & 0x00000F00) >> 8
    port_update = (arg & 0x000000FF)
  else
    major = arg
  end
  @major = major
  @minor = minor || 0
  @update = update || 0
  @patch = patch || 0
  @port_update = port_update || 0
end

Instance Attribute Details

#majorObject (readonly)

The first part of the Oracle version.



17
18
19
# File 'lib/oci8/oracle_version.rb', line 17

def major
  @major
end

#minorObject (readonly)

The second part of the Oracle version.



19
20
21
# File 'lib/oci8/oracle_version.rb', line 19

def minor
  @minor
end

#patchObject (readonly)

The fifth part of the Oracle version.



23
24
25
# File 'lib/oci8/oracle_version.rb', line 23

def patch
  @patch
end

#port_updateObject (readonly)

The fourth part of the Oracle version.



25
26
27
# File 'lib/oci8/oracle_version.rb', line 25

def port_update
  @port_update
end

#updateObject (readonly)

The third part of the Oracle version.



21
22
23
# File 'lib/oci8/oracle_version.rb', line 21

def update
  @update
end

Instance Method Details

#<=>(other) ⇒ Object

:call-seq:

oraver <=> other_oraver -> -1, 0, +1

Compares oraver and other_oraver.

<=> is the basis for the methods <, <=, ==, >, >=, and between?, included from module Comparable.



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/oci8/oracle_version.rb', line 78

def <=>(other)
  cmp = @major <=> other.major
  return cmp if cmp != 0
  cmp = @minor <=> other.minor
  return cmp if cmp != 0
  cmp = @update <=> other.update
  return cmp if cmp != 0
  cmp = @patch <=> other.patch
  return cmp if cmp != 0
  @port_update <=> other.port_update
end

#eql?(other) ⇒ Boolean

:call-seq:

oraver.eql? other -> true or false

Returns true if oraver and other are the same type and have equal values. – This is for class Hash to test members for equality.

Returns:

  • (Boolean)


126
127
128
# File 'lib/oci8/oracle_version.rb', line 126

def eql?(other)
  other.is_a? OCI8::OracleVersion and (self <=> other) == 0
end

#hashObject

:call-seq:

oraver.hash -> integer

Returns a hash based on the value of oraver. – This is for class Hash.



136
137
138
# File 'lib/oci8/oracle_version.rb', line 136

def hash
  to_i
end

#inspectObject

:nodoc:



140
141
142
# File 'lib/oci8/oracle_version.rb', line 140

def inspect # :nodoc:
  "#<#{self.class.to_s}: #{self.to_s}>"
end

#to_iObject

:call-seq:

oraver.to_i -> integer

Returns an integer number contains 5-digit Oracle version.

If the hexadecimal notation is 0xAABCCDEE, major, minor, update, patch and port_update are 0xAA, 0xB, 0xCC, 0xD and 0xEE respectively.

Example

oraver = OCI8::OracleVersion.new('10.2.0.4')
oraver.to_i          # => 169870336
'%08x' % oraver.to_i # => "0a200400"


103
104
105
# File 'lib/oci8/oracle_version.rb', line 103

def to_i
  (@major << 24) | (@minor << 20) | (@update << 12) | (@patch << 8) | @port_update
end

#to_sObject

:call-seq:

oraver.to_s -> string

Returns a dotted version string of the Oracle version.

Example

oraver = OCI8::OracleVersion.new('10.2.0.4')
oraver.to_s          # => '10.2.0.4.0'


115
116
117
# File 'lib/oci8/oracle_version.rb', line 115

def to_s
  format('%d.%d.%d.%d.%d', @major, @minor, @update, @patch, @port_update)
end