Class: ChemistryKit::Catalyst

Inherits:
Object
  • Object
show all
Defined in:
lib/chemistrykit/catalyst.rb

Overview

Serves as a hash wrapper class for injecting data into formulas

Instance Method Summary collapse

Constructor Details

#initialize(data_file) ⇒ Catalyst

this class serves as a standard container for data that can be injected into a formula



10
11
12
13
14
15
# File 'lib/chemistrykit/catalyst.rb', line 10

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



17
18
19
20
# File 'lib/chemistrykit/catalyst.rb', line 17

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

Instance Method Details

#get_value_for(key) ⇒ Object



22
23
24
25
# File 'lib/chemistrykit/catalyst.rb', line 22

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