module Rambling::Trie

Entry point for rambling-trie API.

Constants

VERSION

Current version of the rambling-trie.

Public Class Methods

config() { |properties| ... } click to toggle source

Provides configuration properties for the Rambling::Trie gem. @return [Configuration::Properties] the configured properties of the

gem.

@yield [Configuration::Properties] the configured properties of the

gem.
# File lib/rambling/trie.rb, line 80
def config
  yield properties if block_given?
  properties
end
create(filepath = nil, reader = nil) { |container| ... } click to toggle source

Creates a new Rambling::Trie. Entry point for the rambling-trie API. @param [String, nil] filepath the file to load the words from. @param [Readers::Reader, nil] reader the file parser to get each word. @return [Container] the trie just created. @yield [Container] the trie just created. @see Rambling::Trie::Readers Readers.

# File lib/rambling/trie.rb, line 22
def create filepath = nil, reader = nil
  root = root_builder.call

  Rambling::Trie::Container.new root, compressor do |container|
    if filepath
      reader ||= readers.resolve filepath
      reader.each_word filepath do |word|
        container << word
      end
    end

    yield container if block_given?
  end
end
dump(trie, filepath, serializer = nil) click to toggle source

Dumps an existing trie from memory into disk. By default, it will deduce the correct way to serialize based on the file extension. Available formats are yml, marshal, and zip versions of all the previous formats. You can also define your own. @param [Container] trie the trie to dump into disk. @param [String] filepath the file to dump to serialized trie into. @param [Serializers::Serializer, nil] serializer the object responsible

for trie serialization.

@return [void]

serializing and dumping the trie into disk.

@see Serializers Serializers.

# File lib/rambling/trie.rb, line 70
def dump trie, filepath, serializer = nil
  serializer ||= serializers.resolve filepath
  serializer.dump trie.root, filepath
end
load(filepath, serializer = nil) { |container| ... } click to toggle source

Loads an existing trie from disk into memory. By default, it will deduce the correct way to deserialize based on the file extension. Available formats are yml, marshal, and zip versions of all the previous formats. You can also define your own. @param [String] filepath the file to load the words from. @param [Serializer, nil] serializer the object responsible of loading

the trie from disk

@return [Container] the trie just loaded. @yield [Container] the trie just loaded. @see Rambling::Trie::Serializers Serializers. @note Use of

{https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-load
Marshal.load} is generally discouraged. Only use the +.marshal+
format with trusted input.
# File lib/rambling/trie.rb, line 51
def load filepath, serializer = nil
  serializer ||= serializers.resolve filepath
  root = serializer.load filepath
  Rambling::Trie::Container.new root, compressor do |container|
    yield container if block_given?
  end
end

Private Class Methods

compressor() click to toggle source
# File lib/rambling/trie.rb, line 99
def compressor
  properties.compressor
end
properties() click to toggle source
# File lib/rambling/trie.rb, line 87
def properties
  @properties ||= Rambling::Trie::Configuration::Properties.new
end
readers() click to toggle source
# File lib/rambling/trie.rb, line 91
def readers
  properties.readers
end
root_builder() click to toggle source
# File lib/rambling/trie.rb, line 103
def root_builder
  properties.root_builder
end
serializers() click to toggle source
# File lib/rambling/trie.rb, line 95
def serializers
  properties.serializers
end