Class: Rambling::Trie::Serializers::File

Inherits:
Object
  • Object
show all
Defined in:
lib/rambling/trie/serializers/file.rb

Overview

Basic file serializer. Dumps/loads string contents from files.

Instance Method Summary collapse

Instance Method Details

#dump(contents, filepath) ⇒ Numeric

Dumps contents into a specified filepath.

Parameters:

  • contents (String)

    the contents to dump.

  • filepath (String)

    the filepath to dump the contents to.

Returns:

  • (Numeric)

    number of bytes written to disk.


19
20
21
22
23
# File 'lib/rambling/trie/serializers/file.rb', line 19

def dump contents, filepath
  ::File.open filepath, 'w+' do |f|
    f.write contents
  end
end

#load(filepath) ⇒ String

Loads contents from a specified filepath.

Parameters:

  • filepath (String)

    the filepath to load contents from.

Returns:

  • (String)

    all contents of the file.


11
12
13
# File 'lib/rambling/trie/serializers/file.rb', line 11

def load filepath
  ::File.read filepath
end