Sha256: 2d9f46b3d04c098907f41f156c0c073af9d932db31019e0d706a73d03736b7f4

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

Contents

module CodiceFiscale
  class Configuration
    def initialize
      @options = default
    end

    def csv_folder
      File.join File.dirname(__FILE__), 'codes'
    end

    def default
      {
        :city_codes_csv_path => "#{csv_folder}/city_codes.csv",
        :country_codes_csv_path => "#{csv_folder}/country_codes.csv",
        :city_code => nil,
        :country_code => nil
      }
    end

    def method_missing name, *args, &block
      name = remove_final_equal_char(name).to_sym
      return @options[name] if args.empty? and !block_given?
      @options[name] = block_given? && block || args.first
    end

    def remove_final_equal_char string
      parts = string.to_s.scan(/\A(.*)(\=)\z/).flatten
      parts.empty? ? string : parts.first
    end
  end


  module Configurable
    def self.config
      CodiceFiscale.config
    end

    def config
      Configurable.config
    end
  end


  def self.config
    @config ||= Configuration.new
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codice-fiscale-0.0.6 lib/codice_fiscale/configuration.rb