Class: TriCoreDB::Binary
- Inherits:
-
Object
- Object
- TriCoreDB::Binary
- Defined in:
- lib/tricoredb/params.rb
Overview
Explicit marker for bytes bound to a BLOB column, whatever the String's encoding.
Instance Attribute Summary collapse
-
#bytes ⇒ String
readonly
The bytes, as a binary (ASCII-8BIT) String.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(bytes) ⇒ Binary
constructor
A new instance of Binary.
-
#to_param ⇒ String
The
0x…hex text a BLOB column parses.
Constructor Details
#initialize(bytes) ⇒ Binary
Returns a new instance of Binary.
21 22 23 24 |
# File 'lib/tricoredb/params.rb', line 21 def initialize(bytes) @bytes = bytes.is_a?(Array) ? bytes.pack("C*") : String(bytes).b @bytes.freeze end |
Instance Attribute Details
#bytes ⇒ String (readonly)
Returns the bytes, as a binary (ASCII-8BIT) String.
18 19 20 |
# File 'lib/tricoredb/params.rb', line 18 def bytes @bytes end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
31 32 33 |
# File 'lib/tricoredb/params.rb', line 31 def ==(other) other.is_a?(Binary) && other.bytes == bytes end |
#hash ⇒ Object
36 37 38 |
# File 'lib/tricoredb/params.rb', line 36 def hash bytes.hash end |
#to_param ⇒ String
Returns the 0x… hex text a BLOB column parses.
27 28 29 |
# File 'lib/tricoredb/params.rb', line 27 def to_param "0x#{@bytes.unpack1('H*')}" end |