Class: OCI::ResponseHeaders
- Inherits:
-
Object
- Object
- OCI::ResponseHeaders
- Defined in:
- lib/oci/response_headers.rb
Overview
A readonly, case-insensitive http response header collection
Instance Method Summary collapse
-
#[](key) ⇒ Object
Element Reference-Retrieves the value object corresponding to the key object.
-
#each(&block) ⇒ Object
(also: #each_pair)
Calls block once for each key in hsh, passing the key-value pair as parameters.
-
#each_key(&block) ⇒ Object
Calls block once for each key in hsh, passing the key as a parameter.
-
#each_value(&block) ⇒ Object
Calls block once for each key in hsh, passing the value as a parameter.
-
#empty? ⇒ Boolean
Returns true if hsh contains no key-value pairs.
-
#eql?(other) ⇒ Boolean
Returns true if hash and other are both hashes with the same content.
-
#fetch(key, *args, &block) ⇒ Object
Returns a value from the hash for the given key.
-
#hash ⇒ Object
Compute a hash-code for this hash.
-
#initialize(headers) ⇒ ResponseHeaders
constructor
Initialize the readonly and case-insensitive http response headers with hash object.
-
#key(value) ⇒ Object
Returns the key of an occurrence of a given value.
-
#key?(key) ⇒ Boolean
(also: #has_key?, #include?, #member?)
Returns true if the given key is present in hsh.
-
#keys ⇒ Object
Returns a new array populated with the keys from this hash.
-
#size ⇒ Object
(also: #length)
Returns the number of key-value pairs in the hash.
-
#to_hash ⇒ Object
Returns the hash object.
-
#to_s ⇒ Object
(also: #inspect)
Return the contents of this hash as a string.
-
#value?(value) ⇒ Boolean
(also: #has_value?)
Returns true if the given value is present for some key in hsh.
-
#values ⇒ Object
Returns a new array populated with the values from hsh.
Constructor Details
#initialize(headers) ⇒ ResponseHeaders
Initialize the readonly and case-insensitive http response headers with hash object.
9 10 11 12 13 14 15 16 17 |
# File 'lib/oci/response_headers.rb', line 9 def initialize(headers) @headers = {} return if headers.nil? headers.each do |key, value| key = key.downcase if key.is_a? String @headers[key] = value.is_a?(Array) && value.length == 1 ? value[0] : value end end |
Instance Method Details
#[](key) ⇒ Object
Element Reference-Retrieves the value object corresponding to the key object. If not found, returns nil.
23 24 25 26 |
# File 'lib/oci/response_headers.rb', line 23 def [](key) key = key.downcase if key.is_a? String @headers[key] || nil end |
#each(&block) ⇒ Object Also known as: each_pair
Calls block once for each key in hsh, passing the key-value pair as parameters. If no block is given, an enumerator is returned instead.
32 33 34 |
# File 'lib/oci/response_headers.rb', line 32 def each(&block) @headers.each(&block) end |
#each_key(&block) ⇒ Object
Calls block once for each key in hsh, passing the key as a parameter. If no block is given, an enumerator is returned instead.
40 41 42 |
# File 'lib/oci/response_headers.rb', line 40 def each_key(&block) @headers.each_key(&block) end |
#each_value(&block) ⇒ Object
Calls block once for each key in hsh, passing the value as a parameter. If no block is given, an enumerator is returned instead.
51 52 53 |
# File 'lib/oci/response_headers.rb', line 51 def each_value(&block) @headers.each_value(&block) end |
#empty? ⇒ Boolean
Returns true if hsh contains no key-value pairs.
56 57 58 |
# File 'lib/oci/response_headers.rb', line 56 def empty? @headers.empty? end |
#eql?(other) ⇒ Boolean
Returns true if hash and other are both hashes with the same content.
61 62 63 |
# File 'lib/oci/response_headers.rb', line 61 def eql?(other) @headers.eql?(other) end |
#fetch(key, *args, &block) ⇒ Object
Returns a value from the hash for the given key. If the key cannot be found, there are several options: With no other arguments, it will raise an KeyError exception; if default is given, then that will be returned; if the optional code block is specified, then that will be run and its result returned.
68 69 70 71 |
# File 'lib/oci/response_headers.rb', line 68 def fetch(key, *args, &block) key = key.downcase if key.is_a? String @headers.fetch(key, *args, &block) end |
#hash ⇒ Object
Compute a hash-code for this hash. Two hashes with the same content will have the same hash code (and will compare using eql?).
96 97 98 |
# File 'lib/oci/response_headers.rb', line 96 def hash @headers.hash end |
#key(value) ⇒ Object
Returns the key of an occurrence of a given value. If the value is not found, returns nil.
114 115 116 |
# File 'lib/oci/response_headers.rb', line 114 def key(value) @headers.key(value) end |
#key?(key) ⇒ Boolean Also known as: has_key?, include?, member?
Returns true if the given key is present in hsh.
76 77 78 79 |
# File 'lib/oci/response_headers.rb', line 76 def key?(key) key = key.downcase if key.is_a? String @headers.key?(key) end |
#keys ⇒ Object
Returns a new array populated with the keys from this hash.
119 120 121 |
# File 'lib/oci/response_headers.rb', line 119 def keys @headers.keys end |
#size ⇒ Object Also known as: length
Returns the number of key-value pairs in the hash.
124 125 126 |
# File 'lib/oci/response_headers.rb', line 124 def size @headers.size end |
#to_hash ⇒ Object
Returns the hash object.
135 136 137 |
# File 'lib/oci/response_headers.rb', line 135 def to_hash @headers end |
#to_s ⇒ Object Also known as: inspect
Return the contents of this hash as a string.
104 105 106 |
# File 'lib/oci/response_headers.rb', line 104 def to_s @headers.to_s end |
#value?(value) ⇒ Boolean Also known as: has_value?
Returns true if the given value is present for some key in hsh.
87 88 89 |
# File 'lib/oci/response_headers.rb', line 87 def value?(value) @headers.value?(value) end |
#values ⇒ Object
Returns a new array populated with the values from hsh.
140 141 142 |
# File 'lib/oci/response_headers.rb', line 140 def values @headers.values end |