Class: Ipfs::Multihash

Inherits:
Object
  • Object
show all
Defined in:
lib/multihash.rb

Constant Summary collapse

DEFAULT_LENGTH =
46
VALID_DIGEST_LENGTH =
'm'
FUNCTION_TYPE_CODE =
{
  sha256: 'Q'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

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_lengthObject (readonly)

Returns the value of attribute digest_length.



6
7
8
# File 'lib/multihash.rb', line 6

def digest_length
  @digest_length
end

#digest_valueObject (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_typeObject (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

#rawObject Also known as: to_s



22
23
24
# File 'lib/multihash.rb', line 22

def raw
  "#{@hash_func_type}#{@digest_length}#{@digest_value}"
end