Class: Commons::Util::Properties

Inherits:
Object
  • Object
show all
Defined in:
lib/commons/util/properties.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults = nil) ⇒ Properties

Returns a new instance of Properties.



40
41
42
43
44
45
46
# File 'lib/commons/util/properties.rb', line 40

def initialize(defaults = nil)
  @properties = Hash.new
  
  if defaults != nil
    @defaults = defaults
  end
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



37
38
39
# File 'lib/commons/util/properties.rb', line 37

def properties
  @properties
end

Instance Method Details

#get_property(key, default_value = nil) ⇒ Object



72
73
74
75
# File 'lib/commons/util/properties.rb', line 72

def get_property(key, default_value = nil)
  value = @properties[key]
  return value == nil ? default_value : value
end

#load(file) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/commons/util/properties.rb', line 49

def load(file)
  file.each_line {|line|
    line.strip!
    if line != '' && line[0].chr != '#'
      pos = line.index('=')
      if pos != nil && pos > 1
        key = line[0 ... pos].strip
        value = line[pos + 1 .. -1].strip
        if value[0].chr == '"' && value[-1].chr == '"'
          value = value[1 ... -1]
        end
        set_property(key, value)
      end
    end
  }
end

#property_namesObject



67
68
69
# File 'lib/commons/util/properties.rb', line 67

def property_names
  return @properties.keys
end

#set_property(key, value) ⇒ Object



78
79
80
# File 'lib/commons/util/properties.rb', line 78

def set_property(key, value)
  @properties[key] = value
end