A ruby library to read and write Java properties files, which format is better described in the Java documentation.
Install via Rubygems or Gemfile
$ gem install proper_properties
You can load a valid Java properties file from the file system using a path:
properties = ProperProperties.load("path/to/my.properties")
properties[:foo] # => "bar"
properties['foo'] # => "bar"
If have already the content of the properties file at hand than parse the content as:
properties = ProperProperties.load("foo=bar")
properties[:foo] # => "bar"
properties['foo'] # => "bar"
You can write any Hash-like structure (with symbol or string keys) as a properties file:
hash = {:foo => "bar", "foobar" => "barfoo"}
ProperProperties.write(hash, "path/to/my.properties")
Or if you want to omit the file you can receive the content directly:
hash = {:foo => "bar"}
ProperProperties.generate(hash) # => "foo=bar"
Although ISO 8859-1 is assumed for Java properties files, they normally use UTF-8 encoding. This tool tries to convert them:
"ה" <=> "\u05d4"
The tool also escaped every '=', ' ' and ':' in the name part of a property line:
ProperProperties.generate({"i : like=strange" => "bar"})
# => "i\ \:\ like\=strange=bar"
In Java properties files there is distinction between natural lines and logical lines (than may span several lines by escaping the line terminator characters).
Assume the following input:
my=This is a multi \
line content with only \n one line break
The parses would read:
{:my => "This is a multi line content which only \n one line break"}
In the opposite direction line breaks will be correctly escaped but the generator will never use multi line values.
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- Tnarik Innael (@tnarik)
- Jonas Thiel (@jonasthiel) : original project upto 1f2c4b008d69d0eae1084b1adfdea814e2b29899
For a proper description about the properties file format have a look at the Java Plattform documentation.
This gem is released under the MIT License. See the LICENSE.txt file for further details.