Sha256: eaf131edf43bb580394a78c0ddbe845a51bf2111f78d7f902daf7947effe2404

Contents?: true

Size: 666 Bytes

Versions: 4

Compression:

Stored size: 666 Bytes

Contents

# Encoding: utf-8

require 'csv'

module ChemistryKit
  # Serves as a hash wrapper class for injecting data into formulas
  class Catalyst
    # this class serves as a standard container for data that can be injected into a formula

    def initialize(data_file)
      @data = {}
      CSV.foreach(data_file) do | row |
        @data[row[0].to_sym] = row[1]
      end
    end

    def method_missing(name)
      validate_key name
      @data[name]
    end

    def get_value_for(key)
      validate_key key
      @data[key.to_sym]
    end

    private

      def validate_key(key)
        raise "Unknown \"#{key}\"" unless @data.key?(key.to_sym)
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chemistrykit-3.10.1 lib/chemistrykit/catalyst.rb
chemistrykit-3.10.0 lib/chemistrykit/catalyst.rb
chemistrykit-3.9.1 lib/chemistrykit/catalyst.rb
chemistrykit-3.9.0 lib/chemistrykit/catalyst.rb