Module: JavaProperties::Generating::Generator
- Defined in:
- lib/java-properties/generating/generator.rb
Overview
This module allows generating the content of a properties file base on a Properties object (or any other hash like structure)
Constant Summary collapse
- KEY_VALUE_SEPARATOR =
Character used for key-value separation
'='- DEFAULT_OPTIONS =
Default options
{ :skip_encode_unicode => false, :skip_encode_separators => false, :skip_encode_special_chars => false }.freeze
Class Method Summary collapse
- .build_line(key, value, options) ⇒ Object
- .encoding_skips(is_value, options) ⇒ Object
-
.generate(properties, options = {}) ⇒ String
Generates a properties file content based on a hash.
Class Method Details
.build_line(key, value, options) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/java-properties/generating/generator.rb', line 40 def self.build_line(key, value, ) encoded_key = Encoding.encode!(key.to_s.dup, *encoding_skips(false, )) encoded_value = Encoding.encode!(value.to_s.dup, *encoding_skips(true, )) encoded_key + KEY_VALUE_SEPARATOR + encoded_value end |
.encoding_skips(is_value, options) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/java-properties/generating/generator.rb', line 47 def self.encoding_skips(is_value, ) skips = [] skips << Encoding::SKIP_SEPARATORS if is_value || [:skip_encode_separators] skips << Encoding::SKIP_UNICODE if [:skip_encode_unicode] skips << Encoding::SKIP_SPECIAL_CHARS if [:skip_encode_special_chars] skips end |
.generate(properties, options = {}) ⇒ String
Generates a properties file content based on a hash
29 30 31 32 33 34 35 36 |
# File 'lib/java-properties/generating/generator.rb', line 29 def self.generate(properties, = {}) = DEFAULT_OPTIONS.merge() lines = [] properties.each do |key, value| lines << build_line(key, value, ) end lines.join("\n") end |