class HuffmanTree::Leaf

A Leaf is a kind of Node.

A Leaf has, in addition to the attributes of a Node, a symbol. The width and height are 1, and the offset is 0.5.

Attributes

symbol[R]

The String associated with a weight in a leaf node.

Public Class Methods

new(weight, symbol) click to toggle source

Assign a Numeric weight and a symbol (String) to a leaf.

The width and height are 1, and the offset is 0.5.

Calls superclass method HuffmanTree::Node.new
# File huffman_tree.rb, line 107
def initialize(weight, symbol)
   super(weight, 1, 1, 0.5)
   @symbol = symbol
end

Public Instance Methods

draw(bits='') click to toggle source

Generate JavaScript to draw leaf.

Draw a labeled link to the node. Write the symbol at the end of the link.

# File huffman_tree.rb, line 125
def draw(bits='')
    "#{draw_link(bits)}
     draw_leaf(#{@offset}, #{symbol.dump.dump});"
end
margin(deepest, depth=0) click to toggle source

Number of characters in 'dump' representation of :symbol.

# File huffman_tree.rb, line 115
def margin(deepest, depth=0)
    depth == deepest ?  @symbol.dump.length : 0
end