Class: Rays::Utils::FileUtils::PropertiesFile
- Inherits:
-
Object
- Object
- Rays::Utils::FileUtils::PropertiesFile
- 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
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#initialize(file) ⇒ PropertiesFile
constructor
A new instance of PropertiesFile.
- #write ⇒ Object
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
#properties ⇒ Object (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
#write ⇒ Object
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 |