Class: IniFile
- Inherits:
-
Object
- Object
- IniFile
- Defined in:
- lib/inifile.rb
Overview
Copyright © 2004 Gregoire Lejeune <[email protected]>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Instance Method Summary collapse
- #[](section) ⇒ Object
- #[]=(section, hash) ⇒ Object
- #clear ⇒ Object
-
#initialize(file = nil) ⇒ IniFile
constructor
A new instance of IniFile.
- #load(file) ⇒ Object
- #sections ⇒ Object
- #write(file = nil) ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ IniFile
Returns a new instance of IniFile.
21 22 23 24 25 26 |
# File 'lib/inifile.rb', line 21 def initialize( file = nil ) clear( ) if file.nil? == false and file.empty? == false load( file ) end end |
Instance Method Details
#[](section) ⇒ Object
68 69 70 71 72 |
# File 'lib/inifile.rb', line 68 def [](section) if @hhxData.nil? == false return @hhxData[section] end end |
#[]=(section, hash) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/inifile.rb', line 74 def []=(section, hash) if @hhxData.nil? == true @hhxData = Hash::new( ) @sectionList = [] end @hhxData[section] = hash end |
#clear ⇒ Object
62 63 64 65 66 |
# File 'lib/inifile.rb', line 62 def clear @hhxData = nil @sectionList = nil @xIniFile = nil end |
#load(file) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/inifile.rb', line 28 def load( file ) clear( ) @hhxData = Hash::new( ) @sectionList = [] @xIniFile = file parseFile( ) end |
#sections ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/inifile.rb', line 54 def sections if @hhxData.nil? == false @sectionList.each {|k| yield( k ) } end end |
#write(file = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/inifile.rb', line 36 def write( file = nil ) xWriteFile = @xIniFile if file.nil? == false xWriteFile = file end fIni = open( xWriteFile, "w" ) @sectionList.each {|xSection| hxPairs = @hhData[xSection] fIni.print "[", xSection, "]\n" hxPairs.each{ |xKey, xValue| fIni.print xKey, " = ", xValue, "\n" } fIni.puts "\n" } fIni.close( ) end |