Sha256: 78e91dbb52686daae1a5756b08277d70a7a7e394b630f078b537cab8a5d63d9a

Contents?: true

Size: 704 Bytes

Versions: 4

Compression:

Stored size: 704 Bytes

Contents

module Rambling
  module Trie
    # Provides the String representation behavior for the trie data structure.
    module Stringifyable
      # String representation of the current node, if it is a terminal node.
      # @return [String] the string representation of the current node.
      # @raise [InvalidOperation] if node is not terminal or is root.
      def as_word
        raise Rambling::Trie::InvalidOperation, 'Cannot represent branch as a word' if letter && !terminal?
        to_s
      end

      # String representation of the current node.
      # @return [String] the string representation of the current node.
      def to_s
        parent.to_s << letter.to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rambling-trie-1.0.3 lib/rambling/trie/stringifyable.rb
rambling-trie-1.0.2 lib/rambling/trie/stringifyable.rb
rambling-trie-1.0.1 lib/rambling/trie/stringifyable.rb
rambling-trie-1.0.0 lib/rambling/trie/stringifyable.rb