Class: Avmtrf1::Ini

Inherits:
Object
  • Object
show all
Includes:
EacRubyUtils::SimpleCache
Defined in:
lib/avmtrf1/ini.rb,
lib/avmtrf1/ini/profile.rb

Overview

Leitor de arquivos .ini com suporte a herança de seções/perfis.

Defined Under Namespace

Classes: Profile

Constant Summary collapse

SECTION_NAME_PATTERN =
/\A([^\:]+)(?:\:([^\:]+))?\z/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inifile) ⇒ Ini

Returns a new instance of Ini.

Parameters:

  • ini

    Um [IniFile] ou um caminho de arquivo .ini.


38
39
40
# File 'lib/avmtrf1/ini.rb', line 38

def initialize(inifile)
  @inifile = inifile.is_a?(::IniFile) ? inifile : self.class.inifile_from_file(inifile.to_s)
end

Instance Attribute Details

#inifileObject (readonly)

Returns the value of attribute inifile.


35
36
37
# File 'lib/avmtrf1/ini.rb', line 35

def inifile
  @inifile
end

Class Method Details

.inifile_from_file(path) ⇒ IniFile

Returns .

Returns:


25
26
27
28
29
30
31
32
# File 'lib/avmtrf1/ini.rb', line 25

def inifile_from_file(path)
  raise "\"#{path}\" does not exist or is not a file" unless ::File.file?(path)

  r = ::IniFile.load(path)
  return r if r.is_a?(::IniFile)

  raise "\"#{path}\" not converted to Inifile"
end

.parse_section_name(section_name) ⇒ Object


17
18
19
20
21
22
# File 'lib/avmtrf1/ini.rb', line 17

def parse_section_name(section_name)
  m = SECTION_NAME_PATTERN.match(section_name)
  return [m[1], m[2]] if m

  raise "Section name pattern \"#{SECTION_NAME_PATTERN}\" not match \"#{section_name}\""
end