Module: INIH

Defined in:
lib/inih.rb,
ext/inih/inih.c

Overview

The primary namespace for INIH.

Constant Summary collapse

VERSION =

The current version of ruby-inih.

"1.1.0"

Class Method Summary collapse

Class Method Details

.load(filename) ⇒ Hash

Parse an INI-formatted file into a Hash.

Parameters:

  • filename (String)

    the INI-formatted file to parse

Returns:

  • (Hash)

    the resulting hash

Raises:

  • (RuntimeError)

    if a parse or I/O error occurs



23
# File 'ext/inih/inih.c', line 23

static VALUE mINIH_load(VALUE self, VALUE filename);

.normalize(hsh) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Normalize a parsed INI file's values.



12
13
14
15
16
# File 'lib/inih.rb', line 12

def self.normalize(hsh)
  hsh.map do |k, sect|
    [k, normalize_sect(sect)]
  end.to_h
end

.normalize_sect(sect) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Normalize the values in a section of a parsed INI file.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/inih.rb', line 20

def self.normalize_sect(sect)
  sect.map do |k, v|
    nv = case v
         when "" then nil
         when "true" then true
         when "false" then false
         when /\A-?\d+\Z/ then Integer v
         when /\A-?\d+\.\d+\Z/ then Float v
         else v
         end

    [k, nv]
  end.to_h
end

.parse(string) ⇒ Hash

Parse an INI-formatted string into a Hash.

Parameters:

  • string (String)

    the INI-formatted string to parse

Returns:

  • (Hash)

    the resulting hash

Raises:

  • (RuntimeError)

    if a parse error occurs



14
# File 'ext/inih/inih.c', line 14

static VALUE mINIH_parse(VALUE self, VALUE string);