Class: Rays::Utils::FileUtils::PropertiesFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rays/utils/file_utils.rb

Overview

PropertiesFile allows to work with java .properties files as a ruby hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ PropertiesFile

Returns a new instance of PropertiesFile.



101
102
103
104
105
106
107
108
# File 'lib/rays/utils/file_utils.rb', line 101

def initialize file
  @file_name = file
  @properties = {}
  file = File.open(@file_name, 'r')
  IO.foreach(file) do |line|
    @properties[$1.strip] = $2 if line =~ /([^=]*)=(.*)\/\/(.*)/ || line =~ /([^=]*)=(.*)/
  end
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



99
100
101
# File 'lib/rays/utils/file_utils.rb', line 99

def properties
  @properties
end

Instance Method Details

#writeObject



110
111
112
113
114
# File 'lib/rays/utils/file_utils.rb', line 110

def write
  properties_file = File.new(@file_name, 'w+')
  @properties.each { |key, value| properties_file.puts "#{key}=#{value}\n" }
  properties_file.close
end