Sha256: 55662af5da7b00e42edb589d0aa540884e8843f709b1c98196cca1a85f2f12a4

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

require 'yaml'

module AbsoluteRenamer
    # Class handeling the configuration.
    class Config
        class << self
            # Open and load a Yaml file into the +@conf+ variable.
            # config_path: path of the file to load.
            def load(config_path)
                @conf = YAML::load_file(config_path)

                @conf[:options] ||= {}
                @conf[:options][:format] ||= '$'
                @conf[:options][:ext_format] ||= '$'
            end

            # Returns a configuration value identified by +key+.
            # If +key+ is ignored, returns the +@conf+ hash.
            def get(key = nil)
                return @conf[key] if @conf.has_key?(key)
                return @conf
            end

            # Sets a configuration value in the +@conf+ variable.
            def set(key, value = '')
                @conf[key] = value
            end

            # Returns a configuration value identified by +key+.
            def [](key)
                @conf[key]
            end

            # Sets a configuration value in the +@conf+ variable.
            def []=(key, value)
                @conf[key] = value
            end
        end
    end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
simonc-AbsoluteRenamer-0.9.2 lib/absolute_renamer/config.rb
AbsoluteRenamer-0.9.2 lib/absolute_renamer/config.rb
AbsoluteRenamer-0.9.1 lib/absolute_renamer/config.rb
AbsoluteRenamer-0.9.0 lib/absolute_renamer/config.rb
AbsoluteRenamer-0.9.0.1 lib/absolute_renamer/config.rb
AbsoluteRenamer-0.9.0.2 lib/absolute_renamer/config.rb