Module: VDF

Defined in:
lib/vdf.rb,
lib/vdf/parse.rb,
lib/vdf/version.rb,
lib/vdf/generate.rb

Overview

Main VDF module

Author:

  • sapphyrus

Defined Under Namespace

Classes: Generator, Parser, ParserError

Constant Summary collapse

VERSION =

The current version

"1.0.4"

Class Method Summary collapse

Class Method Details

.generate(object) ⇒ String

Generates a VDF document from a ruby hash.

Parameters:

  • object (Hash)

    the input object

Returns:

  • (String)

    the generated VDF document



40
41
42
# File 'lib/vdf/generate.rb', line 40

def generate(object)
	Generator.generate(object)
end

.parse(input) ⇒ Hash

Parses a VDF document into a Ruby Hash and returns it

For large files, it’s recommended to pass the File object to VDF.parse instead of reading the whole File contents into memory

Examples:

Parse the contents of a VDF String

contents = VDF.parse(string)

Parse the contents of a VDF File

File.open("filename.vdf", "r") do |file|
	contents = VDF.parse(file)
	puts contents.inspect
end

Parameters:

  • input (String, File, #to_str, #each_line)

    the input object

Returns:

  • (Hash)

    the contents of the VDF document, parsed into a Ruby Hash

Raises:



128
129
130
# File 'lib/vdf/parse.rb', line 128

def parse(input)
	Parser.parse(input)
end