Re: Using Ruby to read .properties file


#1

None that I know of without writing code - but there isn’t much to it.
Try this:

def load_properties(properties_filename)
properties = {}
File.open(properties_filename, ‘r’) do |properties_file|
properties_file.read.each_line do |line|
line.strip!
if (line[0] != ?# and line[0] != ?=)
i = line.index(’=’)
if (i)
properties[line[0…i - 1].strip] = line[i + 1…-1].strip
else
properties[line] = ‘’
end
end
end
end
properties
end

Unashamedly taken from http://www.bigbold.com/snippets/posts/show/1311


#2

Thanks a lot for the code

sanchit

“Lock Stephen” removed_email_address@domain.invalid
06/06/2006 07:29 PM
Please respond to
removed_email_address@domain.invalid

To
removed_email_address@domain.invalid (ruby-talk ML)
cc

Subject
Re: Using Ruby to read .properties file

None that I know of without writing code - but there isn’t much to it.
Try this:

def load_properties(properties_filename)
properties = {}
File.open(properties_filename, ‘r’) do |properties_file|
properties_file.read.each_line do |line|
line.strip!
if (line[0] != ?# and line[0] != ?=)
i = line.index(’=’)
if (i)
properties[line[0…i - 1].strip] = line[i + 1…-1].strip
else
properties[line] = ‘’
end
end
end
end
properties
end

Unashamedly taken from http://www.bigbold.com/snippets/posts/show/1311