Module: Rambling::Trie

Defined in:
lib/rambling/trie.rb,
lib/rambling/trie/nodes.rb,
lib/rambling/trie/readers.rb,
lib/rambling/trie/version.rb,
lib/rambling/trie/container.rb,
lib/rambling/trie/nodes/raw.rb,
lib/rambling/trie/comparable.rb,
lib/rambling/trie/compressor.rb,
lib/rambling/trie/enumerable.rb,
lib/rambling/trie/nodes/node.rb,
lib/rambling/trie/inspectable.rb,
lib/rambling/trie/serializers.rb,
lib/rambling/trie/compressible.rb,
lib/rambling/trie/configuration.rb,
lib/rambling/trie/nodes/missing.rb,
lib/rambling/trie/stringifyable.rb,
lib/rambling/trie/serializers/zip.rb,
lib/rambling/trie/nodes/compressed.rb,
lib/rambling/trie/serializers/file.rb,
lib/rambling/trie/serializers/yaml.rb,
lib/rambling/trie/invalid_operation.rb,
lib/rambling/trie/readers/plain_text.rb,
lib/rambling/trie/serializers/marshal.rb,
lib/rambling/trie/configuration/properties.rb,
lib/rambling/trie/configuration/provider_collection.rb

Overview

Entry point for rambling-trie API.

Defined Under Namespace

Modules: Comparable, Compressible, Configuration, Enumerable, Inspectable, Nodes, Readers, Serializers, Stringifyable Classes: Compressor, Container, InvalidOperation

Constant Summary collapse

VERSION =

Current version of the rambling-trie.

'2.2.0'

Class Method Summary collapse

Class Method Details

.config {|Configuration::Properties| ... } ⇒ Configuration::Properties

Provides configuration properties for the Rambling::Trie gem.

Yields:

Returns:


78
79
80
81
# File 'lib/rambling/trie.rb', line 78

def config
  yield properties if block_given?
  properties
end

.create(filepath = nil, reader = nil) {|Container| ... } ⇒ Container

Creates a new Rambling::Trie. Entry point for the Rambling::Trie API.

Parameters:

  • filepath (String, nil) (defaults to: nil)

    the file to load the words from.

  • reader (Reader, nil) (defaults to: nil)

    the file parser to get each word.

Yields:

Returns:

See Also:


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object

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.

Parameters:

  • trie (Container)

    the trie to dump into disk.

  • filepath (String)

    the file to dump to serialized trie into.

  • serializer (Serializer, nil) (defaults to: nil)

    the object responsible of serializing and dumping the trie into disk.

See Also:


68
69
70
71
# 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| ... } ⇒ Container

Note:

Use of Marshal.load is generally discouraged. Only use the `.marshal` format with trusted input.

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.

Parameters:

  • filepath (String)

    the file to load the words from.

  • serializer (Serializer, nil) (defaults to: nil)

    the object responsible of loading the trie from disk

Yields:

Returns:

See Also:


51
52
53
54
55
56
57
# 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