jgoodsen (owner)

Revisions

gist: 169835 Download_button fork
public
Public Clone URL: git://gist.github.com/169835.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
##
## Created a simple Class in ruby to help reading and writing property files
##
 
class JavaProps
  
  attr :file, :properties
 
  #Takes a file and loads the properties in that file
  def initialize file
    @file = file
    @properties = {}
    IO.foreach(file) do |line|
      @properties[$1.strip] = $2 if line =~ /([^=]*)=(.*)\/\/(.*)/ || line =~ /([^=]*)=(.*)/
    end
  end
 
  #Helpfull to string
  def to_s
    output = “File Name #{@file} \n”
    @properties.each {|key,value| output += ” #{key}= #{value} \n” }
    output
  end
 
  #Write a property
  def write_property (key,value)
    @properties[key] = value
  end
 
  #Save the properties back to file
  def save
    file = File.new(@file,”w+”)
    @properties.each {|key,value| file.puts “#{key}=#{value}\n” }
  end
 
end