Class: OCI8::OracleVersion
- Inherits:
-
Object
- Object
- OCI8::OracleVersion
- 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
-
#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) ⇒ Object
:call-seq: oraver <=> other_oraver -> -1, 0, +1.
-
#eql?(other) ⇒ Boolean
:call-seq: oraver.eql? other -> true or false.
-
#hash ⇒ Object
:call-seq: oraver.hash -> integer.
-
#initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil) ⇒ OracleVersion
constructor
Creates a OCI8::OracleVersion object.
-
#inspect ⇒ Object
:nodoc:.
-
#to_i ⇒ Object
:call-seq: oraver.to_i -> integer.
-
#to_s ⇒ Object
:call-seq: oraver.to_s -> string.
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
#major ⇒ Object (readonly)
The first part of the Oracle version.
17 18 19 |
# File 'lib/oci8/oracle_version.rb', line 17 def major @major end |
#minor ⇒ Object (readonly)
The second part of the Oracle version.
19 20 21 |
# File 'lib/oci8/oracle_version.rb', line 19 def minor @minor end |
#patch ⇒ Object (readonly)
The fifth part of the Oracle version.
23 24 25 |
# File 'lib/oci8/oracle_version.rb', line 23 def patch @patch end |
#port_update ⇒ Object (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 |
#update ⇒ Object (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.
126 127 128 |
# File 'lib/oci8/oracle_version.rb', line 126 def eql?(other) other.is_a? OCI8::OracleVersion and (self <=> other) == 0 end |
#hash ⇒ Object
: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 |
#inspect ⇒ Object
:nodoc:
140 141 142 |
# File 'lib/oci8/oracle_version.rb', line 140 def inspect # :nodoc: "#<#{self.class.to_s}: #{self.to_s}>" end |
#to_i ⇒ Object
: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_s ⇒ Object
: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 |