Class: Netfira::WebConnect::OctaWord
- Inherits:
-
Object
- Object
- Netfira::WebConnect::OctaWord
- Defined in:
- lib/netfira/web_connect/components/octa_word.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #base64 ⇒ Object
- #binary ⇒ Object (also: #b)
- #eql?(other) ⇒ Boolean (also: #==)
- #hex ⇒ Object
-
#initialize(binary_digest) ⇒ OctaWord
constructor
A new instance of OctaWord.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(binary_digest) ⇒ OctaWord
Returns a new instance of OctaWord.
23 24 25 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 23 def initialize(binary_digest) @binary = binary_digest.b end |
Class Method Details
.from_base64(digest) ⇒ Object
13 14 15 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 13 def from_base64(digest) new (digest[0..21] << '==').unpack('m').first end |
.from_binary(digest) ⇒ Object Also known as: from
7 8 9 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 7 def from_binary(digest) new digest if digest end |
.from_hex(digest) ⇒ Object
17 18 19 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 17 def from_hex(digest) new [digest].pack('H*') end |
Instance Method Details
#as_json(options = nil) ⇒ Object
65 66 67 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 65 def as_json( = nil) base64 end |
#base64 ⇒ Object
37 38 39 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 37 def base64 [@binary].pack('m0')[0..21] end |
#binary ⇒ Object Also known as: b
27 28 29 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 27 def binary @binary end |
#eql?(other) ⇒ Boolean Also known as: ==
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 49 def eql?(other) case other when Netfira::WebConnect::OctaWord then b == other.b when String case other.length when 16 then other == b when 22 then other == base64 when 32 then other == hex else false end else false end end |
#hex ⇒ Object
33 34 35 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 33 def hex @binary.unpack('H*')[0] end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 45 def inspect "#{self.class.name.demodulize}: #{base64}" end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/netfira/web_connect/components/octa_word.rb', line 41 def to_s base64 end |