Sha256: 42f5b2276bc197e942e869cf678beb71844d9c5beccf21f85ab50de483699717

Contents?: true

Size: 771 Bytes

Versions: 3

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

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
        if letter && !terminal?
          raise Rambling::Trie::InvalidOperation,
            'Cannot represent branch as a word'
        end

        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

3 entries across 3 versions & 1 rubygems

Version Path
rambling-trie-2.5.0 lib/rambling/trie/stringifyable.rb
rambling-trie-2.4.0 lib/rambling/trie/stringifyable.rb
rambling-trie-2.3.1 lib/rambling/trie/stringifyable.rb