Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

homonoid/inidol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Inidol

Pure Ruby atomic-small and super-simple library for transforming Hashes to INI code. Use gem install inidol for install.

API

Inidol has little method, that extends Hash class in Ruby.

Hash.to_ini

Convert Hash to INI string. Example:

require 'inidol'
settings = {
	global: {
		name: 'Bounce',
		author: 'homonoid',
		version: '~1.0.0'
	},
	
	settings: {
		graphics: 'low',
		shadows: false
	}
}
puts settings.to_ini

outputs following INI:

[global]
name=Bounce
author=homonoid
version=~1.0.0

[settings]
graphics=low
shadows=false

String.from_ini

Convert INI string to Hash. Example:

require 'inidol'
require 'pp'

settings = <<-END
	[numbers]
	digits = 12 # will be transformed into number
	version = 1.0.0 # will be transformed into string
	float = 3.14 # will be transformed into float

	[strings]
	simple = "Hello, World!" # followed with quotes
	also = Hello, World! # or without quotes

	[arrays]
	constants[] = 3.14
	constants[] = 2.71
	constants[] = 1.45
END

pp settings.from_ini

outputs following Hash:

{
	:numbers => {
		:digits => 12,
		:version => "1.0.0",
		:float => 3.14
	},
	:strings => {
		:simple => "Hello, World!",
		:also => "Hello, World!"
	},
	:arrays => {
		:constants => [3.14, 2.71, 1.45]
	}
}

Bugs

  • Inserts newline at start of INI. May be fixed using [1..-1].

Releases

No releases published

Packages

No packages published

Languages