Giter VIP home page Giter VIP logo

java-properties's Introduction

JavaProperties

Build Status Code Climate Coveralls RubyGems Gemnasium Inline docs

A ruby library to read and write Java properties files.

Installation

Install via Rubygems

$ gem install java-properties

... or add to your Gemfile

gem "java-properties"

Loading files

You can load a valid Java properties file from the file system using a path:

properties = JavaProperties.load("path/to/my.properties")
properties[:foo] # => "bar"

If have already the content of the properties file at hand than parse the content as:

properties = JavaProperties.load("foo=bar")
properties[:foo] # => "bar"

Writing files

You can write any Hash-like structure as a properties file:

hash = {:foo => "bar"}
JavaProperties.write(hash, "path/to/my.properties")

Or if you want to omit the file you can receive the content directly:

hash = {:foo => "bar"}
JavaProperties.generate(hash)  # => "foo=bar"

Encodings and special chars

As Java properties files normally hold UTF-8 chars in their escaped representation this tool tries to convert them:

"ื”" <=> "\u05d4"

The tool also escaped every '=', ' ' and ':' in the name part of a property line:

JavaProperties.generate({"i : like=strange" => "bar"}) 
# => "i\ \:\ like\=strange=bar"

Multi line and line breaks

In Java properties files a string can be multi line but line breaks have to be escaped.

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.

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

Jonas Thiel (@jonasthiel)

References

For more information about the properties file format have a look at the Java Plattform documenation.

License

This gem is released under the MIT License. See the LICENSE file for further details.

java-properties's People

Contributors

jnbt avatar rrrene avatar splattael avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.