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 78
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 [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 [Serializer, nil] serializer the object responsible of

serializing and dumping the trie into disk.

@see Rambling::Trie::Serializers Serializers.

# File lib/rambling/trie.rb, line 68
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.5.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 97
def compressor
  properties.compressor
end
properties() click to toggle source
# File lib/rambling/trie.rb, line 85
def properties
  @properties ||= Rambling::Trie::Configuration::Properties.new
end
readers() click to toggle source
# File lib/rambling/trie.rb, line 89
def readers
  properties.readers
end
root_builder() click to toggle source
# File lib/rambling/trie.rb, line 101
def root_builder
  properties.root_builder
end
serializers() click to toggle source
# File lib/rambling/trie.rb, line 93
def serializers
  properties.serializers
end