Method: Inifile#initialize

Defined in:
lib/vr/contrib/inifile.rb

#initialize(iniFilename) ⇒ Inifile

Inifile

It makes inifile like Window’s in working directory

section

key=value …

Methods

—deletekey(section,key)

Delete ((|key|)) and associated value in ((|section|)).

—erasesection(section)

Erase ((|section|)) and associated keys and values.

—read( section, key, [default=“”])

Read value associated ((|key|)) in ((|section|)).
If ((|section|)) or ((|key|)) not exists ,value uses ((|default|)).

—write( section, key, value)

Write ((|value|)) in assiciated ((|key|)) and ((|section|)).
If ((|section|)) or ((|key|)) not exists , make them.

—frash

Write into ((|inifilename|)) of instance.


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vr/contrib/inifile.rb', line 33

def initialize(iniFilename) #privatemethod. Use "new(inFilename)" instead.
  sec={}
  section=""
  @fn = Dir.getwd + "/" + iniFilename
  if File.exist?(@fn) then
    f=open @fn
    f.each do |t|
      if t =~ /\[.+\]/ then
        section= t.sub(/\[(.+)\]/,'\1').strip
        sec={section=>{}}
        self.update sec
      elsif t =~/.+=/ then
        a=t.split(/=/)
        val={a[0].strip=>a[1].strip}
        self[section].update(val)
      end
    end
    f.close
  end
end