Class: SDL4R::SdlBinary
- Inherits:
-
Object
- Object
- SDL4R::SdlBinary
- Defined in:
- lib/sdl4r/sdl_binary.rb
Overview
Represents a binary value.
This class was introduced to avoid the confusion between a Ruby String and a binary literal.
Instance Attribute Summary collapse
-
#bytes ⇒ Object
Returns the value of attribute bytes.
Class Method Summary collapse
-
.decode64(s) ⇒ Object
Decodes the specified base-64 encoded string and returns a corresponding SdlBinary instance.
Instance Method Summary collapse
- #==(o) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(bytes) ⇒ SdlBinary
constructor
value
: a String containing the bytes. -
#to_s ⇒ Object
Returns the bytes base64-encoded.
Constructor Details
#initialize(bytes) ⇒ SdlBinary
value
: a String containing the bytes
33 34 35 |
# File 'lib/sdl4r/sdl_binary.rb', line 33 def initialize(bytes) @bytes = bytes end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
30 31 32 |
# File 'lib/sdl4r/sdl_binary.rb', line 30 def bytes @bytes end |
Class Method Details
.decode64(s) ⇒ Object
Decodes the specified base-64 encoded string and returns a corresponding SdlBinary instance. s
might not include the conventional starting and ending square brackets.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sdl4r/sdl_binary.rb', line 57 def self.decode64(s) s = s.delete("\n\r\t ") binary = Base64.decode64(s) if binary.empty? and not s.empty? raise ArgumentError, "bad binary literal" end return SdlBinary.new(binary) end |
Instance Method Details
#==(o) ⇒ Object Also known as: eql?
37 38 39 40 41 |
# File 'lib/sdl4r/sdl_binary.rb', line 37 def ==(o) return true if self.equal?(o) return false if not o.instance_of?(self.class) return self.bytes == o.bytes end |
#hash ⇒ Object
45 46 47 |
# File 'lib/sdl4r/sdl_binary.rb', line 45 def hash return bytes.hash end |
#to_s ⇒ Object
Returns the bytes base64-encoded.
50 51 52 |
# File 'lib/sdl4r/sdl_binary.rb', line 50 def to_s return Base64.encode64(bytes) end |