Class: Ipfs::Multihash
- Inherits:
-
Object
- Object
- Ipfs::Multihash
- Defined in:
- lib/ruby-ipfs-http-client/multihash.rb
Constant Summary collapse
- FUNCTIONS =
[ { name: :sha256, type_code: 0x12, digest_length: 0x20 } ]
Instance Attribute Summary collapse
-
#digest_length ⇒ Object
readonly
Returns the value of attribute digest_length.
-
#hash_func_type ⇒ Object
readonly
Returns the value of attribute hash_func_type.
Instance Method Summary collapse
-
#initialize(multihash) ⇒ Multihash
constructor
A new instance of Multihash.
- #raw ⇒ Object (also: #to_s)
- #to_bytes ⇒ Object
Constructor Details
#initialize(multihash) ⇒ Multihash
Returns a new instance of Multihash.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby-ipfs-http-client/multihash.rb', line 12 def initialize(multihash) @base58_encoded = multihash raise Error::InvalidMultihash, "The hash '#{@base58_encoded}' is invalid." unless @base58_encoded.is_a?(String) @bytes_encoded = to_bytes @function = find_hash_function(@bytes_encoded[0]) raise Error::InvalidMultihash, "The hash func type could not be found" if @function.nil? @hash_func_type = @function[:name] @digest_length = @function[:digest_length] raise Error::InvalidMultihash, "The hash '#{@base58_encoded}' is invalid." unless correct_length? end |
Instance Attribute Details
#digest_length ⇒ Object (readonly)
Returns the value of attribute digest_length.
6 7 8 |
# File 'lib/ruby-ipfs-http-client/multihash.rb', line 6 def digest_length @digest_length end |
#hash_func_type ⇒ Object (readonly)
Returns the value of attribute hash_func_type.
6 7 8 |
# File 'lib/ruby-ipfs-http-client/multihash.rb', line 6 def hash_func_type @hash_func_type end |
Instance Method Details
#raw ⇒ Object Also known as: to_s
37 38 39 |
# File 'lib/ruby-ipfs-http-client/multihash.rb', line 37 def raw @base58_encoded end |