Class: MerkleTree::Leaf Private

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/merkle_tree/leaf.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An object to hold one-time signature

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, left_index, right_index) ⇒ Leaf

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a leaf node



24
25
26
27
28
29
# File 'lib/merkle_tree/leaf.rb', line 24

def initialize(value, left_index, right_index)
  @value = value
  @left_index = left_index
  @right_index = right_index
  @height = 0
end

Instance Attribute Details

#heightObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/merkle_tree/leaf.rb', line 9

def height
  @height
end

#left_indexObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/merkle_tree/leaf.rb', line 13

def left_index
  @left_index
end

#right_indexObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/merkle_tree/leaf.rb', line 15

def right_index
  @right_index
end

#valueObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/merkle_tree/leaf.rb', line 11

def value
  @value
end

Class Method Details

.build(value, position, digest: MerkleTree.default_digest) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/merkle_tree/leaf.rb', line 17

def self.build(value, position, digest: MerkleTree.default_digest)
  new(digest.(value), position, position)
end

Instance Method Details

#<=>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
# File 'lib/merkle_tree/leaf.rb', line 43

def <=>(other)
  value <=> other.value &&
    left_index <=> other.left_index &&
    right_index <=> other.right_index
end

#include?(index) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
# File 'lib/merkle_tree/leaf.rb', line 35

def include?(index)
  (left_index..right_index).cover?(index)
end

#leaf?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


31
32
33
# File 'lib/merkle_tree/leaf.rb', line 31

def leaf?
  true
end

#sizeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/merkle_tree/leaf.rb', line 39

def size
  1
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/merkle_tree/leaf.rb', line 49

def to_h
  { value: value }
end

#to_s(indent = "") ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/merkle_tree/leaf.rb', line 53

def to_s(indent = "")
  indent + value
end