Module: VDF

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

Overview

Main VDF module

Defined Under Namespace

Classes: Generator, Parser, ParserError

Constant Summary collapse

VERSION =

The current version

'1.0.5'

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



42
43
44
# File 'lib/vdf/generate.rb', line 42

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:



135
136
137
# File 'lib/vdf/parse.rb', line 135

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