mdc/lib/parsing/properties_reader.rb
##
# Read the contents of a java properties file into an associative array
# @param [String|IO] file name of properties file
# @param [String] separator the separation character
Read the contents of a java properties file into an associative array
Read the contents of a java properties file into an associative array
def read_file_into_array(file, separator)
      lines = if file.respond_to?(:readlines)
                file.readlines("\n")
              else
                File.readlines(file, "\n", encoding: 'UTF-8')
              end
      result = {}
      regex = Regexp.new("(.*?)#{separator}(.*)")
      lines.each do |line|
        next if /^[ ]*#.*/ =~ line
        regex.match(line) { |m| result[m[1].strip] = m[2].strip }
      end
      result
    end
def read_file_into_array ( file , separator ) lines = if file . respond_to? ( :readlines ) file . readlines ( "\n" ) else File . readlines ( file , "\n" , encoding : 'UTF-8' ) end result = { } regex = Regexp . new ( "(.*?)#{separator}(.*)" ) lines . each do | line | next if / ^[ ]*#.* / =~ line regex . match ( line ) { | m | result [ m [ 1 ] . strip ] = m [ 2 ] . strip } end result end
Read the contents of a java properties file into an associative array
Read the contents of a java properties file into an associative array
# ignore comments # Add entry to the hash
file
<not_specific>
separator
<not_specific>
<not_specific>
separator the separation character
separator the separation character