Class: Ipfs::Multihash
- Inherits:
-
Object
- Object
- Ipfs::Multihash
- Defined in:
- lib/multihash.rb
Constant Summary collapse
- DEFAULT_LENGTH =
46- VALID_DIGEST_LENGTH =
'm'- FUNCTION_TYPE_CODE =
{ sha256: 'Q' }
Instance Attribute Summary collapse
-
#digest_length ⇒ Object
readonly
Returns the value of attribute digest_length.
-
#digest_value ⇒ Object
readonly
Returns the value of attribute digest_value.
-
#hash_func_type ⇒ Object
readonly
Returns the value of attribute hash_func_type.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Multihash
constructor
A new instance of Multihash.
- #raw ⇒ Object (also: #to_s)
Constructor Details
#initialize(hash) ⇒ Multihash
Returns a new instance of Multihash.
14 15 16 17 18 19 20 |
# File 'lib/multihash.rb', line 14 def initialize(hash) @hash_func_type = hash[0] @digest_length = hash[1] @digest_value = hash[2..-1] raise Ipfs::Error::InvalidMultihash, "The hash '#{raw}' is invalid." unless valid? end |
Instance Attribute Details
#digest_length ⇒ Object (readonly)
Returns the value of attribute digest_length.
6 7 8 |
# File 'lib/multihash.rb', line 6 def digest_length @digest_length end |
#digest_value ⇒ Object (readonly)
Returns the value of attribute digest_value.
6 7 8 |
# File 'lib/multihash.rb', line 6 def digest_value @digest_value end |
#hash_func_type ⇒ Object (readonly)
Returns the value of attribute hash_func_type.
6 7 8 |
# File 'lib/multihash.rb', line 6 def hash_func_type @hash_func_type end |
Instance Method Details
#raw ⇒ Object Also known as: to_s
22 23 24 |
# File 'lib/multihash.rb', line 22 def raw "#{@hash_func_type}#{@digest_length}#{@digest_value}" end |