class Pyer::Properties

This class represents the INI file and can be used to parse INI files.

Private Class Methods

new(filename, opts = {}) click to toggle source

Create a new configuration hash

# File lib/pyer/properties.rb, line 7
def initialize(filename, opts = {})
  @filename = filename
  @encoding = opts[:encoding]
  @comment  = opts[:comment]
  @mode = @encoding.nil? ? 'r' : "r:#{@encoding}"
  @settings = {}
  hashing if File.exist? @filename
end

Private Instance Methods

count() click to toggle source

Return count of valid properties

# File lib/pyer/properties.rb, line 17
def count
  @settings.length
end
hashing() click to toggle source
# File lib/pyer/properties.rb, line 28
def hashing
  File.open(@filename, @mode).each_line do |line|
    next if line.length < 3
    next if line[0] == '#' || line[0] == ';' # known comments
    i = line.index('=')
    next if i < 1
    line.chop! if line[-1] == "\n"
    @settings[line[0, i].strip.to_sym] = line[i + 1, line.length - 2].strip
  end
end
method_missing(name) click to toggle source

Return value or nil if name is unknown

# File lib/pyer/properties.rb, line 22
def method_missing(name)
  @settings[name.to_sym]
end