Class: Philiprehberger::IniParser::Serializer

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

Overview

Converts a nested Hash back into an INI-formatted string.

Top-level scalar keys are written as global key=value pairs. Top-level Hash values are written as [section] groups. String values containing special characters are escaped.

Instance Method Summary collapse

Instance Method Details

#serialize(hash) ⇒ String

Serialize a Hash to an INI string.

Parameters:

  • hash (Hash)

    configuration data

Returns:

  • (String)

    INI formatted output



15
16
17
18
19
20
21
# File 'lib/philiprehberger/ini_parser/serializer.rb', line 15

def serialize(hash)
  globals, sections = partition(hash)
  lines = serialize_globals(globals)
  serialize_sections(sections, lines)
  lines << '' unless lines.empty?
  lines.join("\n")
end