Loads properties from a file with lines formatted as 'key=value' into a Hash. Comments (lines starting with #) are skipped, as are lines starting with =. Empty property values (lines ending with =) and property values containing = are included in the Hash.
1
2 def load_properties(properties_filename)
3 properties = {}
4 File.open(properties_filename, 'r') do |properties_file|
5 properties_file.read.each_line do |line|
6 line.strip!
7 if (line[0] != ?# and line[0] != ?=)
8 i = line.index('=')
9 if (i)
10 properties[line[0..i - 1].strip] = line[i + 1..-1].strip
11 else
12 properties[line] = ''
13 end
14 end
15 end
16 end
17 properties
18 end