Class: OCI8::OracleVersion
- Inherits:
-
Object
- Object
- OCI8::OracleVersion
- Includes:
- Comparable
- Defined in:
- lib/oci8/oracle_version.rb
Overview
The data class, representing Oracle version.
Oracle version is represented by five numbers: major, minor, update, patch and port_update.
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
The first part of the Oracle version.
-
#minor ⇒ Object
readonly
The second part of the Oracle version.
-
#patch ⇒ Object
readonly
The fifth part of the Oracle version.
-
#port_update ⇒ Object
readonly
The fourth part of the Oracle version.
-
#update ⇒ Object
readonly
The third part of the Oracle version.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compares
self
andother
. -
#eql?(other) ⇒ true or false
Returns true if
self
andother
are the same type and have equal values. -
#hash ⇒ Integer
Returns a hash based on the value of
self
. -
#initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil) ⇒ OCI8::OracleVersion
constructor
Creates an OCI8::OracleVersion object.
-
#to_i ⇒ Integer
Returns an integer number contains 5-digit Oracle version.
-
#to_s ⇒ Integer
Returns a dotted version string of the Oracle version.
Constructor Details
#initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil) ⇒ OCI8::OracleVersion
Creates an 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.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/oci8/oracle_version.rb', line 64 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
#major ⇒ Object (readonly)
The first part of the Oracle version.
19 20 21 |
# File 'lib/oci8/oracle_version.rb', line 19 def major @major end |
#minor ⇒ Object (readonly)
The second part of the Oracle version.
21 22 23 |
# File 'lib/oci8/oracle_version.rb', line 21 def minor @minor end |
#patch ⇒ Object (readonly)
The fifth part of the Oracle version.
25 26 27 |
# File 'lib/oci8/oracle_version.rb', line 25 def patch @patch end |
#port_update ⇒ Object (readonly)
The fourth part of the Oracle version.
27 28 29 |
# File 'lib/oci8/oracle_version.rb', line 27 def port_update @port_update end |
#update ⇒ Object (readonly)
The third part of the Oracle version.
23 24 25 |
# File 'lib/oci8/oracle_version.rb', line 23 def update @update end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compares self
and other
.
<=> is the basis for the methods <, <=, ==, >, >=, and between?, included from the Comparable module.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/oci8/oracle_version.rb', line 91 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) ⇒ true or false
Returns true if self
and other
are the same type and have equal values.
134 135 136 |
# File 'lib/oci8/oracle_version.rb', line 134 def eql?(other) other.is_a? OCI8::OracleVersion and (self <=> other) == 0 end |
#hash ⇒ Integer
Returns a hash based on the value of self
.
141 142 143 |
# File 'lib/oci8/oracle_version.rb', line 141 def hash to_i end |
#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.
115 116 117 |
# File 'lib/oci8/oracle_version.rb', line 115 def to_i (@major << 24) | (@minor << 20) | (@update << 12) | (@patch << 8) | @port_update end |
#to_s ⇒ Integer
Returns a dotted version string of the Oracle version.
126 127 128 |
# File 'lib/oci8/oracle_version.rb', line 126 def to_s format('%d.%d.%d.%d.%d', @major, @minor, @update, @patch, @port_update) end |