Class: Philiprehberger::TomlKit::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/toml_kit/serializer.rb

Overview

Converts a Ruby Hash into a TOML v1.0 formatted string.

Type mapping:

- String -> TOML basic string (with escapes)
- Integer -> TOML integer
- Float -> TOML float (handles inf, nan)
- true/false -> TOML boolean
- Time -> TOML offset or local date-time
- Date -> TOML local date
- Hash with :hour/:minute/:second -> TOML local time
- Array -> TOML array (or array of tables if all elements are Hashes)
- Hash -> TOML table

Instance Method Summary collapse

Instance Method Details

#serialize(hash) ⇒ String

Returns TOML formatted string.

Parameters:

  • hash (Hash)

    Ruby hash to serialize

Returns:

  • (String)

    TOML formatted string



23
24
25
26
27
# File 'lib/philiprehberger/toml_kit/serializer.rb', line 23

def serialize(hash)
  lines = []
  serialize_table(hash, [], lines)
  lines.join("\n") << "\n"
end