Class: Universa::KeyAddress
- Inherits:
-
RemoteAdapter
- Object
- Delegator
- RemoteAdapter
- Universa::KeyAddress
- Defined in:
- lib/universa/keys.rb
Overview
The com.icodici.crypto.KeyAddress
extension. As it is immutable, caching is used to avoid unnecessary UMI calls.
Class Method Summary collapse
-
.from_packed(binary_string) ⇒ Object
Unpack from binary bytes.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare KeyAddress with another KeyAddress or its string or even binary representation.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#packed ⇒ String
returns binary representation.
-
#to_s ⇒ String
String form of the key which could be used to unpack it back.
Methods inherited from RemoteAdapter
#__getobj__, #__setobj__, #initialize, #inspect, invoke_static, remote_class, remote_class_name, remote_field, static_method
Constructor Details
This class inherits a constructor from Universa::RemoteAdapter
Class Method Details
.from_packed(binary_string) ⇒ Object
Unpack from binary bytes
154 155 156 157 |
# File 'lib/universa/keys.rb', line 154 def self.from_packed(binary_string) binary_string.force_encoding 'binary' KeyAddress.new(binary_string) end |
Instance Method Details
#==(other) ⇒ Object
Compare KeyAddress with another KeyAddress or its string or even binary representation. Analyzes string length to select proper strategy.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/universa/keys.rb', line 167 def == other if other.is_a?(KeyAddress) super elsif other.is_a?(String) case other.size when 37, 53 # it is for sure packed representation packed == other else # is should be string representation then to_s == other end else false end end |
#eql?(other) ⇒ Boolean
188 189 190 |
# File 'lib/universa/keys.rb', line 188 def eql?(other) self == other end |
#hash ⇒ Object
184 185 186 |
# File 'lib/universa/keys.rb', line 184 def hash to_s.hash end |
#packed ⇒ String
returns binary representation. It is not a string representation!
161 162 163 |
# File 'lib/universa/keys.rb', line 161 def packed @packed ||= get_packed.force_encoding 'binary' end |
#to_s ⇒ String
String form of the key which could be used to unpack it back
148 149 150 |
# File 'lib/universa/keys.rb', line 148 def to_s @string ||= toString() end |