require "yaml" module SCSSBeautifier class Config DEFAULT = File.realpath(File.join(File.dirname(__FILE__), "..", "..", "data", "default_config.yml")).freeze def initialize(config_location) @config = parse_config(config_location.to_s) end def parse_config(config_location) config_contents = read_config(config_location) YAML.load(config_contents) end def formatters enabled_formatters = [] @config["formatters"].each do |formatter, options| if options["enabled"] klass = SCSSBeautifier::Formatters.const_get(formatter.split("_").map(&:capitalize).join) enabled_formatters << klass.new(options) end end enabled_formatters end def options options_with_key_symbols = {} @config["options"].each do |k, v| options_with_key_symbols[:"#{k}"] = v end options_with_key_symbols end private def read_config(config_location) location = File.exists?(config_location) ? config_location : DEFAULT File.read(location) end end end