Class: ChemistryKit::Chemist
- Inherits:
-
Object
- Object
- ChemistryKit::Chemist
- Defined in:
- lib/chemistrykit/chemist.rb,
lib/chemistrykit/chemist/repository/csv_chemist_repository.rb
Overview
Chemist namespace
Defined Under Namespace
Modules: Repository
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(key, type) ⇒ Chemist
constructor
A new instance of Chemist.
-
#method_missing(name, *arguments) ⇒ Object
allow this object to be set with arbitrary key value data.
- #with(chemist) ⇒ Object
Constructor Details
#initialize(key, type) ⇒ Chemist
Returns a new instance of Chemist.
10 11 12 13 14 |
# File 'lib/chemistrykit/chemist.rb', line 10 def initialize(key, type) @key = key.to_s @type = type.to_s @data = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments) ⇒ Object
allow this object to be set with arbitrary key value data
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chemistrykit/chemist.rb', line 28 def method_missing(name, *arguments) value = arguments[0] name = name.to_s if name[-1, 1] == '=' key = name[/(.+)\s?=/, 1] @data[key.to_sym] = value unless instance_variables.include? "@#{key}".to_sym else @data[name.to_sym] end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/chemistrykit/chemist.rb', line 8 def data @data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/chemistrykit/chemist.rb', line 8 def key @key end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/chemistrykit/chemist.rb', line 7 def type @type end |
Instance Method Details
#with(chemist) ⇒ Object
22 23 24 25 |
# File 'lib/chemistrykit/chemist.rb', line 22 def with(chemist) send("#{chemist.type}=", chemist) self end |